_debug_uheapmin -- Release Unused Memory in User Heap

Format

#include <umalloc.h>
int _debug_uheapmin(Heap_t heap, const char *file, size_t line);

Language Level: Extension
_debug_uheapmin is the debug version of _uheapmin. Like _uheapmin, it returns all unused memory blocks from the specified heap to the operating system.

To return the memory, _debug_uheapmin calls the release_fn you supplied when you created the heap with _ucreate. If you do not supply a release_fn, _debug_uheapmin has no effect and returns 0.

In addition, _debug_uheapmin makes an implicit call to _uheap_check to validate the heap.

_debug_uheapmin works just like _debug_heapmin except that you specify the heap to use; _debug_heapmin always uses the default heap.

To use _debug_uheapmin, you must compile with the debug memory (/Tm) compiler option. This option maps all _uheapmin calls to _debug_uheapmin.

Note: The /Tm option maps all calls to memory management functions (including heap-specific versions and tiled versions for OS/2) to their debug counterparts. To prevent a call from being mapped, parenthesize the function name.

Return Value
If successful, _debug_uheapmin returns 0. A nonzero return value indicates failure. If the heap specified is not valid, _debug_uheapmin generates an error message with the file name and line number where the call to _debug_uheapmin was made.

Example
This example creates a heap and allocates memory from it, then uses _debug_heapmin to release the memory.

Note: You must compile this example with the /Tm option to map the _uheapmin calls to _debug_uheapmin.

#include <stdlib.h>
#include <stdio.h>
#include <string.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 = (char*)_umalloc(myheap, 60000))) {
      puts("Cannot allocate memory from user heap.\n");
      exit(EXIT_FAILURE);
   }
   memset(ptr, 'x', 60000);
   free(ptr);
   /* _debug_uheapmin will attempt to return the freed object to the system */
   if (0 != _uheapmin(myheap)) {
      puts("_debug_uheapmin returns failed.\n");
      exit(EXIT_FAILURE);
   }
   return 0;
}


Managing Memory with Multiple Heaps
Memory Management


_heapmin -- Release Unused Memory from Default Heap
_ucreate -- Create a Memory Heap
_udump_allocated -- Get Information about Allocated Memory in Heap
_uheap_check -- Validate User Memory Heap
_uheapmin -- Release Unused Memory
/Tm compiler option