Syntax
#include <umalloc.h> void *_umalloc(Heap_t heap, size_t size);Description
_umalloc works just like malloc, except that you specify the heap to use; malloc always allocates from the default heap. A debug version of this function, _debug_umalloc, is also provided.
If the heap does not have enough memory for the request, _umalloc calls the getmore_fn that you specified when you created the heap with _ucreate.
To reallocate or free memory allocated with _umalloc, use the non-heap-specific realloc and free. These functions always check what heap the memory was allocated from.
This example creates a heap and uses _umalloc to allocate memory from the heap.
#include <stdlib.h> #include <stdio.h> #include <umalloc.h> int main(void) { Heap_t myheap; char *ptr; /* Use default heap as user heap */ myheap = _udefault(NULL); if (NULL == (ptr = _umalloc(myheap, 100))) { puts("Cannot allocate memory from user heap."); exit(EXIT_FAILURE); } free(ptr); return 0; }Related Information