tags:

views:

404

answers:

6

I wonder if stack size can grow like heap does during runtime?

+5  A: 

The amount of stack used certainly increases, as you allocate local variables and make function calls. Whether the stack's maximum size can grow is technically undefined, but in practice is generally constant. You can make the constant bigger with a flag to the OS, but usually each thread gets a certain size of stack. When you use too much, it's a stack overflow.

Crashworks
Is there command to see the stack size that is determined by the OS ?
tsubasa
What are you trying to solve? When asking a question, tell us your goal, not your plan.
GMan
@tsubasa: On Windows the stack size is part of the PE header in the image file. To inspect the stack size in an image use dumpbin /headers.
Brian Rasmussen
+1  A: 

I think that the executable stack size is defind by the compiler/linker.. so you can change it but not on runtime. You can change the stack size of a thread. + everything is compiler and os specific, so there is no single answer here.

Dani
A: 

From what I can remember stacks generally operate under the assumption that they exist in a contiguous memory range. Basically the expect the next stack frame to be in the next bit of memory (this helps it run faster not having to do instruction look up). Like others have said it is possible but i don't think it is widely used.

Jason Tholstrup
+1  A: 

The stack size actually allocated can grow on modern desktop operating systems.

In practice it is implemented in terms of the memory management unit. As memory is accessed beyond the current committed pages of the stack, new memory pages are committed in. Only the pages that are actually used (plus one guard page usually) are used in RAM. Maximum stack space can be controlled through system resource limits. For example on POSIX.1-2001 you can query the process maximum stack size with getrlimit().

On the other hand, old operating systems and many embedded systems, lacking a hardware-based memory management unit, do set a fixed limit on the stack size.

laalto
A: 

A thread's stack space is set by the compiler. My compiler will reserve 2Mb of space. And will commit 1 Mb.

Of course you can change your compilers default stack size, or you can start a new thread with a larger stack size by calling CreateThread. http://msdn.microsoft.com/en-us/library/ms682453%28VS.85%29.aspx

Jason
A: 

yes. i think the answers is true

khawla hussein
This provides no information
Odrade
But it answers the question, which does not give much information either.
PostMan