8.4.1 Walking the Global Heap

The GlobalInfo function fills a GLOBALINFO structure with information about the global heap. This information includes the total number of items, the number of free items, and the number of “least recently used” (LRU) items on the global heap. The information enables the application to determine how much memory to allocate for a global-heap walk. The application must allocate the memory before starting the walk. If the application allocates any memory after starting the walk, the results of the heap walk will be corrupt.

The GlobalFirst function fills a GLOBALENTRY structure with information about the first object on the global heap. This information includes the structure size, the size and address of the object, the lock count, and so on.

You use GlobalFirst to begin a walk through the global heap. The GlobalNext function continues the walk by filling a GLOBALENTRY structure with information about the next object on the global heap.

The GlobalEntryHandle function fills a GLOBALENTRY structure with information about a global object whose handle or selector is known. The GlobalEntryModule function fills a GLOBALENTRY structure with information about a specific segment in a module. You use GlobalEntryHandle or GlobalEntryModule, rather than GlobalFirst, to begin a walk through the global heap at a specific object, rather than at the first object on the global heap.