Could not allocate memory

前端 未结 3 1525
-上瘾入骨i
-上瘾入骨i 2021-01-22 17:15

In my C code I am allocating memory for 2d array double E[2000][2000]; but when I run it gets a runtime error Segmentation fault(core dumped) and when

3条回答
  •  佛祖请我去吃肉
    2021-01-22 18:10

    It depends on where you allocate the array. Using stack space will probably cause an overflow (unless you get the linker to allocate an extra large stack).

    For example, this might not work

    int main()
    {
        double E[2000][2000];   // Likely an overflow
    }
    

    However, moving the array to the static memory area

    double E[2000][2000];
    
    int main()
    {
       // use E here
    }
    

    will probably avoid the problem.

提交回复
热议问题