1 typedef struct _MYDATA { 2 LIST_ENTRY ListEntry; 3 ULONG X; 4 ULONG Y; 5 }MYDATA, * PMYDATA; 6 void LookasideTest() 7 { 8 //初始化Lookaside对象 9 PAGED_LOOKASIDE_LIST pageList; 10 ExInitializePagedLookasideList(&pageList, NULL, NULL, 0, sizeof(MYDATA), '1234', 0); 11 //sizeof(MYDATA)对应的参数表示每次分配内存的单位,'1234'是一个tag就是给lookaside的一个标签,没啥用。 12 PMYDATA MyObjectArray[50]; 13 //模拟频繁使用lookaside分配内存 14 for (int i = 0; i < 50; i++) 15 { 16 MyObjectArray[i] = (PMYDATA)ExAllocateFromPagedLookasideList(&pageList); 17 } 18 //模拟频繁释放内存 19 for (int i = 0; i < 50; i++) 20 { 21 ExFreeToPagedLookasideList(&pageList, MyObjectArray[i]); 22 MyObjectArray[i] = NULL; 23 } 24 ExDeletePagedLookasideList(&pageList); 25 26 }