MichaelXanadu
MichaelXanadu

Reputation: 505

Warning message regarding stack size

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).

Upvotes: 11

Views: 11502

Answers (2)

Alfred
Alfred

Reputation: 139

I found that such warnings must be taken seriously. I had a declaration

{ // some local branch deep inside a function 
char T[2000000];  
  ...
}

left by mistake somewhere deep inside a big function. The function always crashed immediatly after entry to the function, even if the declaration in the local branch was far away, and I never got there with the debugger. It was difficult to find in MS Visual Studio, even when code analysis gave me a warning.

Upvotes: 2

rrirower
rrirower

Reputation: 4590

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.

Upvotes: 8

Related Questions