Warning message regarding stack size

2019-06-17 01:21发布

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

2条回答
对你真心纯属浪费
2楼-- · 2019-06-17 01:32

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.

查看更多
地球回转人心会变
3楼-- · 2019-06-17 01:38

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.

查看更多
登录 后发表回答