Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Heap node structure

When applications allocate heap memory, heap nodes are placed next to each other in memory. Each node has four parts, as shown in the following figure:

Node content and size

An allocated heap node contains the following:

  • HNode header: first 20 bytes, fixed length.
  • Usable memory: at least 1 byte, upper limit determined by available memory.
  • Right padding: 0-31 bytes. Usable memory plus right padding is always a multiple of 8.
  • HNode trailer: 4 bytes.

A free heap node contains the following:

  • HNode header: first 20 bytes, fixed length.
  • Usable memory: at least 8 bytes, upper limit determined by available memory, always a multiple of 8.
  • Right padding: 0 bytes. Usable memory plus right padding is always a multiple of 8.
  • HNode trailer: 4 bytes.

The smallest possible heap node size is 32 bytes.

Allocated heap node header format

An allocated node has the HNode header format:

  • void *pLink1 -- the handle of the node used when memory is designated as moveable.
  • void *pLink2 -- the node ID, which indicates the owner of the node.
  • void *pLink3 -- points at the debug string (file, line number, etc.)
  • uint32 dwSize -- the sum of the sizes of the usable memory and right padding in this node.
  • uint32 dwFlags -- various flags and bitfields.

The usable memory part of an allocated node is owned by the caller. The heap code does not examine or modify the memory. The right padding of an allocated heap node is not initialized or examined.

The HNode trailer of an allocated node is a pointer (HNode *pNode) to the HNode structure at the beginning of the node.

Free heap node header format

A free node has the HNode header format:

  • void *pLink1 -- pointer to the previous node.
  • void *pLink2 -- pointer to the next node.
  • void *pLink3 -- NULL (unused)
  • uint32 dwSize -- the size of the usable memory in this node.
  • uint32 dwFlags -- various flags and bitfields.

The usable memory of a free heap node and the right padding of a free heap node is not initialized or examined.

The HNode trailer of a free node is a pointer (HNode *pNode) to the HNode structure at the beginning of the node.