How do I specify the size of stack in MSVC++ ?

Posted on 2005-04-01
Medium Priority
Last Modified: 2010-04-24
   I use Microsoft Visual Studio C++ 6.0. I need to develop a new executable on a new project. But I don't know how to specify the size of the stack.

Question by:pascal_lalonde
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 13684795
Project | Settings | Link | Output

Reserve = total stack allocation
Commit = amount of physical memory to allocate at a time

You can leave both empty (you get a 1MB stack by default).
You can also specify a total stack value but leave the commit value empty.
If you do specify a commit value, the higher it is, the better the performance (that is, if you DO need a large stack for your function calls - e.g. if you have deep recursion). However, a higher commit value means greater memory requirements at runtime.
If there isn't enough physical memory on the system, the performance will obviously suffer greatly due to swapping.


Author Comment

ID: 13686297
Hello Radu,

1) What do you mean by:

"Commit = amount of physical memory to allocate at a time"

  Does it mean the maximum size of a buffer dynamically allocated i.e. allocated with malloc() or calloc() or new ?

2) In a multithreaded program, does the Reserve specify the size of the stack of ONE thread or the total size of all the stacks of all the threads?


Accepted Solution

rcarlan earned 400 total points
ID: 13686381
stack is just memory. Like any other memory in Win32, it's virtual. In order for a process to access/use virtual memory, it needs to be mapped to physical memory (i.e. committed).

The "reserve" controls how big your stack can grow. Go over this limit and you'll get an exception.
The "commit" controls how much of the "reserve" is allocated at a time. You get "commit" bytes to start with, then, if/when you go over (just before) the O/S will give you another "commit" bytes. Obviously, all these "commit" blocks are in contiguous virtual memory space, though physically they can reside in different places (including on the HDD).

These values are default values for all threads created by the process corresponding to the executable. However, when you create a thread programmatically, you can specify the desired stack size (i.e. override the reserve).


Author Comment

ID: 13696808
Thank you!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question