Format
#include <stdlib.h> /* also in <malloc.h> */ int _debug_theapmin(const char *file, size_t line);
Language Level: Extension
_debug_theapmin is the debug version of _theapmin. Like
_theapmin, it returns all unused blocks of tiled memory to the
tiled runtime heap.
In addition, _debug_theapmin makes an implicit call to _theap_check to validate the heap.
To use _debug_theapmin, you must compile with the debug memory (/Tm) and tiled memory (/Gt) compiler options. These options map all _heapmin calls to _debug_theapmin.
Note: The /Tm /Gt options map all calls to regular memory management functions to their tiled debug versions. To prevent a call from being mapped, parenthesize the function name.
_debug_theapmin works just like _debug_heapmin except that it releases only memory allocated with the tiled memory management functions.
Return Value
If successful, _debug_theapmin returns 0. A non-zero
return value indicates failure. If the heap specified is not
valid, _debug_theapmin generates an error message with the file
name and line number where the call to _debug_theapmin was made.
Example
This example allocates 60000 bytes of memory, then frees
it. The freed memory is kept in the default runtime heap until
the call to _debug_theapmin returns it to the operating system.
Because no errors are detected by _theap_check, no messages are
generated.
Note: You must compile this example with the /Tm /Gt options to map the _heapmin calls to _debug_theapmin.
#include <stdlib.h> #include <stdio.h> #include <string.h>
int main(void)
{
char *ptr;
/* Allocate a large object from the system. */
if (NULL == (ptr = (char*)malloc(60000))) {
puts("Could not allocate memory block.\n");
exit(EXIT_FAILURE);
}
memset(ptr, 'x', 60000);
/* The free will keep large object in runtime. */ free(ptr);
/* _debug_theapmin will attempt to return the freed object to the system. */
if (0 != _heapmin()) {
puts("_debug_theapmin returns failed.\n");
exit(EXIT_FAILURE);
}
return 0;
}
![]()
Managing Memory
with Multiple Heaps
Memory Management
![]()
![]()
_debug_heapmin -- Release Unused Memory in
the Default Heap
_debug_tcalloc -- Reserve and Initialize
Tiled Memory
_debug_tfree -- Release Tiled Memory
_debug_tmalloc -- Reserve Tiled Memory
![]()
_heapmin -- Release Unused Memory from
Default Heap
_theap_check -- Validate User Memory Heap
![]()
<malloc.h>
<stdlib.h>
/Tm compiler option
/Gt compiler option