DosSubFreeMem frees a block of memory that was previously allocated by DosSubAllocMem.
Call DosSubFreeMem to free a block of memory in the heap when you are finished with that memory block.
The following code fragment frees a block of memory that was previously allocated from a heap. DosSubFreeMem returns the block to the heap. Assume that the Offset variable has been previously set to the address of the initialized heap, and that the BlockOffset variable has been previously set to the address of the block to be returned to the heap.
#define INCL_DOSMEMMGR /* Memory Manager values */ #include <os2.h> #include <stdio.h> PVOID pOffset; /* Offset of the heap to which the */ /* block is to be freed */ PVOID pBlockOffset; /* Offset of memory block to be freed */ ULONG ulSize; /* Size in bytes of block to be freed */ APIRET ulrc; /* Return code */ ulSize = 102; /* Return 102 bytes. This will be rounded */ /* to 104 bytes (a multiple of 8 bytes). */ ulrc = DosSubFreeMem(pOffset, pBlockOffset, ulSize); if (ulrc != 0) { printf("DosSubFreeMem error: return code = %ld", ulrc); return; }