DosSubSetMem can also be used to increase the size of a previously initialized heap. The heap size can be increased up to the size of the memory object that contains it.
The size of the heap is rounded up to the next higher multiple of 8 bytes.
The following code fragment increases the size of a heap. Assume that the Offset variable was previously loaded with the virtual address of the memory object.
#define INCL_DOSMEMMGR /* Memory Manager values */ #include <os2.h> #include <stdio.h> PVOID pOffset; /* Address of the heap to be used for suballocation */ ULONG ulFlags; /* Flags describing the memory object being resized */ ULONG ulSize; /* Size in bytes to increase the size of the heap */ APIRET ulrc; /* Return code */ ulSize = 20000; /* Indicate a heap size increase of 20000 bytes */ /* DOSSUB_INIT set to initialize memory for suballocation */ ulFlags = DOSSUB_INIT | DOSSUB_SPARSE_OBJ; ulrc = DosSubSetMem(pOffset, ulFlags, ulSize); if (ulrc != 0) { printf("DosSubSetMem error: return code = %ld", ulrc); return; }
In this example, the heap is incremented, and that memory commitment is managed internally within subsequent DosSubAllocMem calls.
When using DosSubSetMem to increase the size of the heap, the Flags parameter must have the same setting as when the heap was initialized.
Note: Do not call DosSetMem to change the allocation attribute or access protection attributes of any pages spanned by a memory object that the suballocation functions are managing. Otherwise, unpredictable results could occur.
Call DosSubUnsetMem when finished with the heap that was set up with DosSubSetMem. This enables the suballocation function to free the resources that it uses to manage the heap. When you are through with the memory object that the heap was part of, use DosFreeMem to free the memory object.