Syntax
#include <umalloc.h> Heap_t _udefault(Heap_t heap);Description
This change affects only the thread where you called _udefault.
The initial default heap is The Developer's Toolkit run-time heap. To restore or explicitly set The Developer's Toolkit run-time heap as the default, call _udefault with the argument _RUNTIME_HEAP.
You can also use _udefault to find out which heap is being used as the default by specifying NULL for the heap parameter. The default heap remains the same.
For more information about creating and using heaps, see "Managing Memory" in the VisualAge C++ Programming Guide.
This example creates a fixed-size heap myheap and uses _udefault to make it the default heap. The call to malloc then allocates memory from myheap. The second call to _udefault restores the original default heap.
#define INCL_DOSMEMMGR /* Memory Manager values */ #include <os2.h> #include <bsememf.h> /* Get flags for memory management */ #include <stdlib.h> #include <stdio.h> #include <umalloc.h> int main(void) { void *initial_block; APIRET rc; Heap_t myheap, old_heap; char *p; /* Call DosAllocMem to get the initial block of memory */ if (0 != (rc = DosAllocMem(&initial_block, 65536, PAG_WRITE | PAG_READ | PAG_COMMIT))) { printf("DosAllocMem error: return code = %ld\n", rc); exit(EXIT_FAILURE); } /* Create a fixed size heap starting with the block declared earlier */ if (NULL == (myheap = _ucreate(initial_block, 65536, _BLOCK_CLEAN, _HEAP_REGULAR, NULL, NULL))) { puts("_ucreate failed."); exit(EXIT_FAILURE); } if (0 != _uopen(myheap)) { puts("_uopen failed."); exit(EXIT_FAILURE); } /* myheap is used as default heap */ old_heap = _udefault(myheap); /* malloc will allocate memory from myheap */ p = malloc(100); memset(p, 'x', 10); /* Restore original default heap */ _udefault(old_heap); free(p); if (0 != _uclose(myheap)) { puts("_uclose failed"); exit(EXIT_FAILURE); } if (0 != (rc = DosFreeMem(initial_block))) { printf("DosFreeMem error: return code = %ld\n", rc); exit(EXIT_FAILURE); } return 0; }Related Information