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.
To use the Unit Heap Manager, a unit heap must be created. The following functions create and destroy unit heaps.
|Creates the unit heap.|
|Creates the unit heap. Alignment and heap options can be specified.|
|Destroys the unit heap.|
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.
The following functions allocate and free memory blocks.
|Allocates a memory block from the unit heap.|
|Frees a memory block.|
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.
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.
The Unit Heap Manager can get the number of allocatable memory blocks (that is, the number of available chunks). Shown in the following function.
|Returns the number of allocatable memory blocks.|
2013/05/08 Automated cleanup pass.
2010/11/01 Initial version.