参考:https://devpress.csdn.net/cloud/63268204fd0b112779162383.html
Answer a question
In many dynamic programming and graph problems it is required to do long depth recursion.
I am currently using vscode and mingw in windows for my c++ programs. But in default,as per my knowledge windows has 1MB max stack size .So I gets segmentation fault / stackoverflow problems. I know pretty well that I can change every recursion in loop,but i don’t wanna that stuff.
In some programming contest like Google Hashcode,Facebook Hackercup , they give large input and if I run that input in my machine it faces segmentation fault / stackoverflow problems.
Now what i need is to increase max stack size.
I found some approaches and here is my questions.
g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 Untitled1.cpp -o a.exe
It works pretty well when I use this command in windows command prompt. But it gives error in vscode terminal(i don’t know why.) I found this command here.
I found somewhere #pragma comment(linker, “/STACK:2000000”), but i didn’t understood this clearly.
Is there anyway to change max stack size once in vscode, so that i do not need to specify every time when i compile ?
I just want to increase max stack size ,
Answers
VSCode uses powershell as its shell and commas are special characters for powershell. You need to put them inside quotes.
g++ -O2 -std=c++11 -Wall "-Wl,--stack=268435456" Untitled1.cpp -o a.exe
should work.
在vscode中本质上只需要把-Wl,–stack=268435456加上引号即可