Before you create a heap, you need to get the block of memory that will make up the heap.
You can get this block of memory by statically allocating it, or by calling one of the following APIs:.
Make sure the block is large enough to satisfy all the memory requests your program will make of it, as well as the internal information for managing the heap. Once the block is fully allocated, further allocation requests to the heap will fail.
The internal information requires _HEAP_MIN_SIZE bytes (_HEAP_MIN_SIZE is defined in <umalloc.h>); you cannot create a heap smaller than this. Add the amount of memory your program requires to this value to determine the size of the block you need to get.
Also make sure the block is the correct type for the heap you are creating:
Once you have the block of memory, create the heap with _ucreate.
Example of Creating a Fixed-Size Heap
Heap_t fixedHeap; /* this is the "heap handle" */
static char block[_HEAP_MIN_SIZE + 5000]; /* get memory for internal info*/
/* plus 5000 bytes for the heap */
fixedHeap = _ucreate(block, (_HEAP_MIN_SIZE+5000), /* block to use */
!_BLOCK_CLEAN, /* memory is not set to 0 (1)*/
_HEAP_REGULAR, /* regular memory (2)*/
NULL, NULL); /* (3) */
Notes:
![]()
Memory Management Functions
Types of Memory