本文主要是介绍在vscode终端terminal加大栈空间How to increase max stack size in c++ using vscode,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
参考: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加上引号即可
这篇关于在vscode终端terminal加大栈空间How to increase max stack size in c++ using vscode的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!