_theapmin -- Release Unused Tiled Memory (OS/2)

Format

#include <stdlib.h>  /* also in <malloc.h> */
int _theapmin(void);

Language Level: Extension
_theapmin returns all unused tiled memory from the runtime heap to the operating system. _theapmin works just like _heapmin, except that it returns only tiled memory; _heapmin returns only regular memory.

You can call _theapmin explicitly, or specify the gen(tiledmemory) compiler option to map all _heapmin calls to _theapmin.

Note: When you specify gen(tiledmemory), all calls to regular debug memory management functions (calloc and so on) are mapped to their tiled equivalents. However, if you parenthesize the function calls, they are not mapped.

A debug version of this function, _debug_theapmin, is also available. Use the alloc(debug) option to map _theapmin calls to _debug_theapmin.

Return Value
If successful, _theapmin returns 0; otherwise, it returns -1.

Example
This example allocates and frees memory from the tiled runtime heap, and then uses _theapmin to return any unused memory to the tiled heap.

Note: You must compile this example with the gen(tiledmemory) option to enable tiled memory.

#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);
   /* _theapmin will attempt to return the freed object to the system. */
   if (0 != _theapmin()) {
      puts("_debug_theapmin returns failed.\n");
      exit(EXIT_FAILURE);
   }
   return 0;
}


Memory Management


_debug_heapmin -- Release Unused Memory
_debug_theapmin -- Release Unused Tiled Memory
_heapmin -- Release Unused Memory from Default Heap
_tcalloc -- Reserve Tiled Storage Block
_tfree -- Free Tiled Storage Block
_tmalloc -- Reserve Tiled Storage Block
_trealloc -- Reallocate Tiled Storage Block
_uheapmin -- Release Unused Memory in User Heap
<malloc.h>
<stdlib.h>
alloc miscellaneous option
tiledmemory code generation option