stack limitations

  • Thread starter Thread starter Peter Oliphant
  • Start date Start date
P

Peter Oliphant

Hey, is there a limit to the stack size? I realize of course there must be,
but how is this determined/set? Or does it self adjust up to, say, available
memory (and possibly virtual memory from hard drives)? My current project
can be set to be from very-stack-intensive to not-so-stack-intensive. The
more stack-intensive it is the faster the code will run, but it can
conceivable want to put huge amounts of info on the stack (there are
potentiqlly recursive processes involved).

Can I determine such things as max stack size (read/write), total stack
already used (read), etc.?

[==P==]
 
Hey, is there a limit to the stack size? I realize of course there must be,
but how is this determined/set?

Have a look at "Thread Stack Size" in MSDN.

Dave
 
Hey, is there a limit to the stack size? I realize of course there must be,
but how is this determined/set?

The default size is set in the executable's header (IMAGE_OPTIONAL_HEADER.SizeOfStackReserve,
IMAGE_OPTIONAL_HEADER.SizeOfStackCommit). It can be changed
using /stack linker option, or by the second parameter of CreateThread function.
Or does it self adjust up to, say, available memory (and possibly virtual memory from hard drives)?

Reserved size cannot grow, committed size can grow up to the reserved size (when the reserved size
is reached, stack overflow exception is thrown).
Can I determine such things as max stack size (read/write),

You should look at the size of the virtual memory region reserved for the stack, using any tool
that can display virtual memory map (e.g. WinDbg's !address and !vadump commands).
Programmatically you can check it using VirtualQuery function.

Here you can find some related information:
http://support.microsoft.com/default.aspx?scid=kb;en-us;315937
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/vclrf_resetstkoflw.asp
total stack already used (read), etc.?

In debugger, you can use this in Watch window (when debugging in Native mode):

Currently committed size:
((unsigned long*)@TIB)[1] - ((unsigned long*)@TIB)[2]

Currently used size:
((unsigned long*)@TIB)[1] - ESP

Regards,
Oleg
[VC++ MVP]
 
Back
Top