Syntax
#include <umalloc.h> int _uclose(Heap_t heap);Description
Once you have closed the heap, use _udestroy to destroy it and return all its memory to the operating system.
Note: If the heap is shared, you must close it in all processes that share it before you destroy it, or undefined results will occur.
You cannot close The Developer's Toolkit run-time heap (_RUNTIME_HEAP).
For more information about creating and using heaps, see "Managing Memory" in the VisualAge C++ Programming Guide.
If successful, _uclose returns 0. A nonzero return value indicates failure. Passing _uclose a heap that is not valid results in undefined behavior.
The following example creates and opens a heap, and then performs operations on it. It then calls _uclose to close the heap before destroying it.
#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; 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); } p = _umalloc(myheap, 100); memset(p, 'x', 10); 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