Platform SDK: Memory

PROCESS_HEAP_ENTRY

The PROCESS_HEAP_ENTRY structure contains information about a heap element. The HeapWalk function uses a PROCESS_HEAP_ENTRY structure to enumerate the elements of a heap.

typedef struct _PROCESS_HEAP_ENTRY {
    PVOID lpData;
    DWORD cbData;
    BYTE cbOverhead;
    BYTE iRegionIndex;
    WORD wFlags;
    union {
        struct {
            HANDLE hMem;
            DWORD dwReserved[ 3 ];
        } Block;
        struct {
            DWORD dwCommittedSize;
            DWORD dwUnCommittedSize;
            LPVOID lpFirstBlock;
            LPVOID lpLastBlock;
        } Region;
    };
} PROCESS_HEAP_ENTRY, *LPPROCESS_HEAP_ENTRY; 

Members

lpData
Pointer to the data portion of the heap element.

To initiate a HeapWalk heap enumeration, set lpData to NULL.

If PROCESS_HEAP_REGION is used in the wFlags member, lpData points to the first virtual address used by the region.

If PROCESS_HEAP_UNCOMMITTED_RANGE is used in wFlags, lpData points to the beginning of the range of uncommitted memory.

cbData
Specifies the size, in bytes, of the data portion of the heap element.

If PROCESS_HEAP_REGION is used in wFlags, cbData specifies the total size, in bytes, of the address space that is reserved for this region.

If PROCESS_HEAP_UNCOMMITTED_RANGE is used in wFlags, cbData specifies the size, in bytes, of the range of uncommitted memory.

cbOverhead
Specifies the size, in bytes, of the data used by the system to maintain information about the heap element. These overhead bytes are in addition to the cbData bytes of the data portion of the heap element.

If PROCESS_HEAP_REGION is used in wFlags, cbOverhead specifies the size, in bytes, of the heap control structures that describe the region.

If PROCESS_HEAP_UNCOMMITTED_RANGE is used in wFlags, cbOverhead specifies the size, in bytes, of the control structures that describe this uncommitted range.

iRegionIndex
Handle to the heap region that contains the heap element. A heap consists of one or more regions of virtual memory, each with a unique region index.

In the first heap entry returned for most heap regions, HeapWalk uses the PROCESS_HEAP_REGION in the wFlags member. When this value is used, the members of the Region structure contain additional information about the region.

The HeapAlloc function sometimes uses the VirtualAlloc function to allocate large blocks from a growable heap. The heap manager treats such a large block allocation as a separate region with a unique region index. HeapWalk does not use PROCESS_HEAP_REGION in the heap entry returned for a large block region, so the members of the Region structure are not valid. You can use the VirtualQuery function to get additional information about a large block region.

wFlags
Specifies properties of the heap element. Some values affect the meaning of other members of this PROCESS_HEAP_ENTRY data structure. The following values are defined.
Value Meaning
PROCESS_HEAP_REGION The heap element is located at the beginning of a region of contiguous virtual memory in use by the heap.

The lpData member of the structure points to the first virtual address used by the region; the cbData member specifies the total size, in bytes, of the address space that is reserved for this region; and the cbOverhead member specifies the size, in bytes, of the heap control structures that describe the region.

The Region structure becomes valid. The dwCommittedSize, dwUnCommittedSize, lpFirstBlock, and lpLastBlock members of the structure contain additional information about the region.

PROCESS_HEAP_UNCOMMITTED_RANGE The heap element is located in a range of uncommitted memory within the heap region.

The lpData member points to the beginning of the range of uncommitted memory; the cbData member specifies the size, in bytes, of the range of uncommitted memory; and the cbOverhead member specifies the size, in bytes, of the control structures that describe this uncommitted range.

PROCESS_HEAP_ENTRY_BUSY The heap element is an allocated block.

If PROCESS_HEAP_ENTRY_MOVEABLE is also specified, the Block structure becomes valid. The hMem member of the Block structure contains a handle to the allocated, moveable memory block.

PROCESS_HEAP_ENTRY_MOVEABLE This value must be used with PROCESS_HEAP_ENTRY_BUSY, indicating that the heap element is an allocated block.

The block was allocated with LMEM_MOVEABLE or GMEM_MOVEABLE, and the Block structure becomes valid. The hMem member of the Block structure contains a handle to the allocated, moveable memory block.

PROCESS_HEAP_ENTRY_DDESHARE This value must be used with PROCESS_HEAP_ENTRY_BUSY, indicating that the heap element is an allocated block.

Block
This structure is valid only if both the PROCESS_HEAP_ENTRY_BUSY and PROCESS_HEAP_ENTRY_MOVEABLE are specified in wFlags.

The members of the Block structure are as follows.
Member Description
hMem Contains a handle to the allocated, moveable memory block.
dwReserved Reserved; not used.

Region
This structure is valid only if the wFlags member specifies PROCESS_HEAP_REGION.

The members of the Region structure are as follows.
Member Description
dwCommittedSize Specifies the number of bytes in the heap region that are currently committed as free memory blocks, busy memory blocks, or heap control structures.

This is an optional field that is set to zero if the number of committed bytes is not available.

dwUnCommittedSize Specifies the number of bytes in the heap region that are currently uncommitted.

This is an optional field that is set to zero if the number of uncommitted bytes is not available.

lpFirstBlock Pointer to the first valid memory block in this heap region.
lpLastBlock Pointer to the first invalid memory block in this heap region.

Requirements

  Windows NT/2000: Requires Windows NT 3.5 or later.
  Windows 95/98: Unsupported.
  Header: Declared in Winbase.h; include Windows.h.

See Also

Memory Management Overview, Memory Management Structures, GlobalAlloc, HeapAlloc, HeapWalk, VirtualAlloc, VirtualQuery