问题描述
我正在尝试进行涉及大量计算和值的模拟.
I'm trying to run a simulation that involves a large amount of calculations and values.
我有一个问题,那就是大型数组会导致程序在声明任何变量之前就崩溃了.我不确定这是由于我的代码还是由于我的操作系统拒绝运行该程序.
I've got an issue in that large arrays cause the program to crash before it's even declared any variables. I'm not sure if this is due to my code or due to my operating system refusing to run the program.
使程序崩溃的代码是:
long double adsorption[2][4][5][10001]
此数组应使用大约10 ^ 6个字节,而SIZE_MAX为10 ^ 19,因此我对它崩溃的原因感到困惑. (程序在任务管理器中为64位)
This array should use about 10^6 bytes, and SIZE_MAX is 10^19, so I'm confused as to why it's crashing. (Program is 64 bit in Task Manager)
我在具有12 Gb内存的Windows 7 64bit上运行,其中10 Gb通常是免费的.编译器是MinGW-w64
I'm running on Windows 7 64bit with 12 Gb of memory, of which 10 Gb is generally free. Compiler is MinGW-w64
抱歉,如果这很基础,我来自物理学背景,而不是编码!
Apologies if this is quite basic, I'm from a physics background, not coding!
欢呼
推荐答案
adsorption
被分配在堆栈上,并且肯定溢出了堆栈.因此,错误.
adsorption
is being allocated on the stack, and it must be overflowing the stack. Hence the error.
使用malloc
和family在堆上分配大块数据.
Use malloc
and family to allocate large chunks of data on the heap.
修改
或者将其设为静态-@Matt McNabb谢谢! :-)
Or make it static -- @Matt McNabb thanks! :-)
这篇关于C程序因大型阵列而崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!