The Unit Heap Manager

The Unit Heap Manager allocates only memory blocks with the size that is specified at the time that the unit heap is created. This memory manager is for allocating and deallocating memory blocks that have a fixed size. The unit heap does not have a management region for memory blocks which makes the heap more memory efficient. This section provides an overview of the Unit Heap Memory Manager.

Creating Heaps

To use the Unit Heap Manager, a unit heap must be created. The following functions create and destroy unit heaps.

Functions for Creating and Destroying Heaps
MEMCreateUnitHeapCreates the unit heap.
MEMCreateUnitHeapExCreates the unit heap. Alignment and heap options can be specified.
MEMDestroyUnitHeapDestroys the unit heap.

Allocating Memory Blocks

Allocating and Freeing Memory Blocks

The Unit Heap Manager manages the heap regions in chunks of a specified size. Memory block allocation refers to allocating these chunks.

Available chunks are linked as one linked list (free chunk list). The pointer to the next free chunk is placed at the starting address of the chunk. There are not pointers for in use chunks. (There is also no management region.) When allocating memory blocks, the manager returns the memory block that is linked to the start address of this free chunk list. When freeing a memory block that is in use, the manager links the memory block to the start address of the available chunk list.

Figure 4-1 Allocating Memory for the Unit Heap

The following functions allocate and free memory blocks.

Functions for Allocating and Freeing Memory Blocks
MEMAllocFromUnitHeapAllocates a memory block from the unit heap.
MEMFreeToUnitHeapFrees a memory block.

Allocating the Minimum Memory Block Size

Even though the Unit Heap Manager does not have a memory block management region, the minimum alignment of allocated memory blocks must be on a 4-byte boundary. Allocating a 1-byte memory block consumes 4 bytes of memory.

Specifying Alignment

The Unit Heap Manager can specify the alignment at heap creation. It does not do this for each allocated memory block. All allocated memory blocks will have the same alignment. In the MEMCreateUnitHeapEx function, you can specify 4, 8, 16 or 32 as alignment values. The MEMCreateUnitHeap function does not specify alignment; the alignment value is always a value of 4.

Acquiring the Number of Allocatable Memory Blocks

The Unit Heap Manager can get the number of allocatable memory blocks (that is, the number of available chunks). Shown in the following function.

Function for Getting the Number of Allocatable Memory Blocks
MEMCountFreeBlockForUnitHeapReturns the number of allocatable memory blocks.

Revision History

2013/05/08 Automated cleanup pass.
2010/11/01 Initial version.