- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
When stack overflow occuring, increasing stack reserve size is helpful while commit size isn't.
Would experts explain the difference bewteen reserve and commit size, and when to increase reserve size and when to increase commit size?
Thanks!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Google: stack reserve commit
https://docs.microsoft.com/en-us/cpp/build/reference/stack-stack-allocations
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks, Jim.
I have read some docs like that. According to the docs, I think commit have higher priority than reserve, since commit memory will allocate physical memory at a time, and reserve memory just reserve size in virtual memory.
But set commit size to a larger number can not solve stack overflow which can be solved by setting reserve size. Why?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do not think that you can commit (one or more times accumulatively) more than reserve. IOW reserve must be set appropriately, and commit (if used by the runtime system) affects the size of the block committed to the page file/RAM (limited to the extent of the reserve size).
reserve == Block out this amount of Virtual Memory Address range for use as stack (not necessarily taking any resources until first used)
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My usual recommendation is to set the option /heap-arrays (Fortran > Optimization > Heap Arrays > 0). This causes temporaries and automatic arrays to be allocated on the heap rather than the stack.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Steve, Your advise is very valuable!
And Thanks Jim!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a Fortran DLL and a C++ executable. The article that Jim references says to only set stack and heap for exe. Is this really the case? How do I handle large arrays in the dll?
Michael
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There is nothing you can do in the DLL to affect the stack size. My advice is to build the DLL with /heap-arrays enabled.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using a set of procedures called fox to read in xml. When I enable /heap-arrays the fox code crashes. It gives me an unhandled break and the locations are not even consistent .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
>>When I enable /heap-arrays the fox code crashes.
Enable all compile time and run time diagnostics. The run time diagnostics may require a console window, or for Windows Program without console window, set the environment variable FORT0 to a file specification for stderr messages, and set environment variable FORT6 to that for stdout messages.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you enable /heap-arrays > 0. Do you have to set the size allocation for the heap anywhere else?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
To track errors, look at additional environment variables
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Do not set the value of /heap-arrays to anything but zero. Non-zero values are not useful. You are not setting the size of the heap. Theoretically, that value for /heap-arrays allows the compiler to keep small things on the stack and allocate large temps on the heap, but in practice the situations where it can do that are so restricted that it is pointless.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page