Syntax
#include <umalloc.h> int _uheapmin(Heap_t heap);Description
_uheapmin works just like _heapmin, except that you specify the heap to use; _heapmin always uses the default heap. A debug version of this function, _debug_uheapmin, is also provided.
To return the memory, _uheapmin calls the release_fn you supplied when you created the heap with _ucreate. If you did not supply a release_fn, _uheapmin has no effect and simply returns 0.
If successful, _uheapmin returns 0. A nonzero return value indicates failure. Passing _uheapmin a heap that is not valid has undefined results.
The following example creates a heap and then allocates and frees a large block of memory from it. It then calls _uheapmin to return free blocks of memory to the system.
#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);
/* Allocate a large object */
if (NULL == (ptr = _umalloc(myheap, 60000))) {
puts("Cannot allocate memory from user heap.");
exit(EXIT_FAILURE);
}
memset(ptr, 'x', 60000);
free(ptr);
/* _uheapmin will attempt to return the freed object to the system */
if (0 != _uheapmin(myheap)) {
puts("_uheapmin failed.");
exit(EXIT_FAILURE);
}
return 0;
}
Related Information