JitendraJat
JitendraJat

Reputation: 53

How to increase max stack size in c++ using vscode

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.

  1. 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. enter image description here

  2. I found somewhere #pragma comment(linker, "/STACK:2000000"), but i didn't understood this clearly.

  3. 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 ,

Upvotes: 2

Views: 5938

Answers (1)

n. m. could be an AI
n. m. could be an AI

Reputation: 119847

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.

Upvotes: 3

Related Questions