Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

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

   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.

Regards!
0
pascal_lalonde
Asked:
pascal_lalonde
  • 2
  • 2
1 Solution
 
rcarlanCommented:
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.

Radu
0
 
pascal_lalondeAuthor Commented:
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?

  Regards.
0
 
rcarlanCommented:
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).

Radu
0
 
pascal_lalondeAuthor Commented:
Thank you!
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now