1 //////////////////////////////////////////////////////////////////////////
2 // Lookaside测试
3 // Lookaside一般在以下情况使用:
4 // 1.每次申请固定大小的内存
5 // 2.频繁申请释放内存
6
7 void LookasideTest()
8 {
9 KdPrint(("Entering LookasideTest function\n"));
10 PAGED_LOOKASIDE_LIST lookAside;
11
12 // 初始化一个分页Lookaside对象
13 // 如果初始化非分页Lookaside对象应该调用ExInitializeNPagedLookasideList
14 ExInitializePagedLookasideList(&lookAside, NULL, NULL, 0, sizeof(MYDATA), '1234', 0);
15 #define ARRAY_NUMBER 10
16 PMYDATA arr[ARRAY_NUMBER];
17 KdPrint(("Now allocating memory...\n"));
18 // 模拟以下频繁地申请内存
19 for (int i = 0; i < ARRAY_NUMBER; i++)
20 {
21 arr[i] = (PMYDATA)ExAllocateFromPagedLookasideList(&lookAside);
22 }
23 KdPrint(("Now freeing memory...\n"));
24 // 模拟频繁地回收内存
25 for (int i = 0; i < ARRAY_NUMBER; i++)
26 {
27 ExFreeToPagedLookasideList(&lookAside, arr[i]);
28 arr[i] = NULL;
29 }
30
31 KdPrint(("Deleteing lookaside object...\n"));
32 // 释放lookaside对象
33 ExDeletePagedLookasideList(&lookAside);
34 KdPrint(("Leaving LookasideTest()\n"));
35 }