环境是win10+VS2015 int common_subsequence[1000][1000]声明在mian函数中,运行到这步栈溢出; int common_subsequence[100][100]声明在main函数中,不会发生栈溢出; int common_subsequence[1000][1000]声明为全局,不会发生栈溢出。 究竟怎么回事?有什么建议吗
The default stack size under windows is 1mb, 4*1000*1000 is about 4mb, so calling main will cause stack overflow.
common_subsequence is an automatic variable, and the memory allocation of the object will be completed before the function starts, which means that the overflow occurs before the first line of code of the main function is executed.
It is recommended to use dynamic memory allocation + smart pointers, or use container classes directly.
The default stack size under windows is 1mb,
4*1000*1000
is about 4mb, so calling main will cause stack overflow.common_subsequence is an automatic variable, and the memory allocation of the object will be completed before the function starts, which means that the overflow occurs before the first line of code of the main function is executed.
It is recommended to use dynamic memory allocation + smart pointers, or use container classes directly.