如何处理MINGW中的小堆栈尺寸?
当我在Linux虚拟机中对其进行测试时,我的代码
#include <stdio.h>
//#define arraySize 5
#define arraySize 500
void func(double B[arraySize][arraySize])
{
B[0][0] = 5;
}
int main(void) {
double Ar2D[arraySize][arraySize];
func(Ar2D);
printf("%f", Ar2D[0][0]);
}
可以正常工作,但是当我在mingw中运行它时,如果将阵列设置为500,它会崩溃(如果将数组设置为5,则在Mingw中正常工作)。解决此问题的最佳方法是什么?
I have the following code
#include <stdio.h>
//#define arraySize 5
#define arraySize 500
void func(double B[arraySize][arraySize])
{
B[0][0] = 5;
}
int main(void) {
double Ar2D[arraySize][arraySize];
func(Ar2D);
printf("%f", Ar2D[0][0]);
}
Code works fine when I test it in a linux virtual machine, but when I run it in minGW, it crashes if I set arraySize to 500 (works fine in minGW if I set arraySize to 5). What is the best way to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您真的应该避免将堆栈用于大事。
这也是安全风险,因为黑客滥用堆栈溢出WAN(例如,尝试尝试运行任意代码)。
更好的是使用堆,您可以通过替换为此来做到这一点
,
当然不要忘记
free(ar2d);
You really should avoid using the stack for large things.
It's also a security risk as stack overflows wan be abused by hackers (e.g. to try to attempt running arbitrary code).
Better is to use the heap, you can do this by replacing
with
and of course don't forget to
free(Ar2D);