If you have created a heap with a fixed size, you can add blocks of memory to it with _uaddmem. This can be useful if you have a large amount of memory that is allocated conditionally. Like the starting block, you must first get the block to add to the heap by using an API or by allocating it statically. Make sure the block you add is the same type of memory as the heap you are adding it to.
Using _uaddmem is the only way to increase the size of a fixed heap.
The following code fragments add 64K to fixedHeap:
![]()
void *newblock; /* get memory block from operating system */ DosAllocMem(newblock, 65536, PAG_COMMIT | PAG_WRITE | PAG_READ); _uaddmem(fixedHeap, /* heap to add to */ newblock, 65536, /* block to add */ _BLOCK_CLEAN); /* DosAllocMem sets memory to 0 */
![]()
void *newblock; /* get memory block from operating system */ newblock = VirtualAlloc(NULL,65536,SYS_COMMIT, SYS_READWRITE) _uaddmem(fixedHeap, /* heap to add to */ newblock, 65536, /* block to add */ _BLOCK_CLEAN); /* VirtualAlloc sets memory to 0 */
For every block of memory you add, a small number of bytes from it are used to store internal information. To reduce the total amount of overhead, it is better to add a few large blocks of memory than many small blocks.