Compuholic
Compuholic

Reputation: 388

Visual C++ /HEAP Linker-Option

I currently have some trouble with the Heap in a program of mine. While I was googling my way through the internet to find solutions I came across a page from the MSDN that describes some linker options for heap allocation that I don't understand.

The documentation says that you can set the Heapsize with /HEAP.

I always knew that the stack size was fixed and that makes sense to me. But I always thought that the Heap is variable in size. To add some more confusion I found that the default value is 1MB. I have written lots of programs that use more than 1 MB of memory.

What exactly does the /HEAP Option do then?

Thanks

Upvotes: 0

Views: 1858

Answers (2)

marinara
marinara

Reputation: 538

windows gives .exes (processes) memory by giving them read/write acess to pages of memory. To the C++ programmer, it should be left to the operating system, never to be messed with

/HEAP 1,000,000 means that an .exe starts up with 1,000,000 bytes worth of pages... TO START WITH. Changing this value shouldn't affect anything. Windows automatically pages in memory. It's just a hint for windows to give this process the memory it needs for performance.

Upvotes: 1

Ben Voigt
Ben Voigt

Reputation: 283684

I think you are confusing the OS heap (HeapAlloc function) which is controlled by the PE header, in turn set by this linker option, and your C++ runtime library dynamic allocation (malloc, new) which probably grab memory directly from the OS using VirtualAlloc and don't use the OS heap.

For more information on the OS heap parameters, read the MSDN documentation for CreateHeap.

Upvotes: 1

Related Questions