How to Increase the Heap Size for the Process
Every program that runs on your computer uses memory. The "heap" is the area of memory used for dynamic memory allocation. In a C program, objects are placed on the "heap", and built-in datatypes such as integer and long are placed on the "stack." The stack is a smaller, faster area of memory that is allocated by last in, first out. Global and static variables also are stored on the "heap" and remain in memory until the program completes. The size of the heap is a predefined number of pages; however, more pages can be allocated to the heap.
Instructions
-
-
1
Ge the handle to the default heap of the calling process within your C program using "GetProcessHeap." Define a variable to hold the handle called "hHandle." If "hHandle" is null, call "GetLastError" to get the failure message.
-
2
Using "hHandle", call "HeapAlloc" to allocate memory to that process' heap. Serialization ensures that two threads do not access the same block of memory; therefore, only use the "HEAP_NO_SERIALIZE" parameter when the application has only one thread or the application handles its own thread calls to the memory heap. You will also need to pass the number of bytes to allocate to "HeapAlloc."
-
-
3
Use "VirtualAlloc" to reserve a block of pages for the process. You can make additional calls to "VirtualAlloc" to commit individual pages so as not to consume storage space until the running process needs it.
To allocate memory that is defaulted to zero and allows read/write access to the committed regions of the pages, type:
DWORD dsize = 468178553;
VirtualAlloc(NULL,dsize ,MEM_COMMIT,PAGE_READWRITE);
-
1
References
- Photo Credit Thinkstock/Comstock/Getty Images