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