在vscode终端terminal加大栈空间How to increase max stack size in c++ using vscode

文章讲述了作者在使用VSCode编译C++程序时遇到栈溢出问题,因为默认Windows系统栈大小限制。寻求如何在VSCode中全局设置最大堆栈大小,以便于处理大型输入并避免在编程竞赛中出现错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考: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加上引号即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值