I use Visual Studio 2010
with Code Analysis
activated. In my code there's a line allocating some memory in a function:
TCHAR someString[40000];
The code analysis throws a warning message:
warning C6262: Function uses '40000' bytes of stack: exceeds /analyze:stacksize'16384'. Consider moving some data to heap
I wonder if I should take the warning serious. Do I have to face some real trouble if I allocate some memory on the stack > 16384? Or is it just a general warning message which reminds me that I have to take care for my stack size in general? As far as I know the default stack size is 1MB (if you use Visual Studio).
If you do, exceeding the stack limit is usually considered a segmentation violation, and systems with enough memory management to detect it will send a SIGSEGV when it happens.
The stack size limit is the maximum size of the stack for a process, in units of 1024 bytes. The stack is a per-thread resource that has unlimited hard and soft limits.
If the stack would be allowed to grow arbitrarily large, these errors (like infinite recursion) would be caught very late, only after the operating systems resources are exhausted. This is prevented by setting an arbitrary limit to the stack size.
It's allocated by the OS on execution of a process. FWIW, stack size is not fixed, it expands at runtime as necessary, but stack limit is fixed.
Admittedly, that message can be confusing since VS (project properties) does report that the default is 1M. However, if you look at the text of the warning, you'll note that the limit is actually 16k for Code Analysis. Follow the steps at the bottom of that link to correct the warning.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With