Declare large array on Stack

后端 未结 4 1063
我寻月下人不归
我寻月下人不归 2020-12-03 15:45

I am using Dev C++ to write a simulation program. For it, I need to declare a single dimensional array with the data type double. It contains 4200000

4条回答
  •  感动是毒
    2020-12-03 16:10

    Are there any reasons you want this on the stack specifically?

    I'm asking because the following will give you a construct that can be used in a similar way (especially accessing values using array[index]), but it is a lot less limited in size (total max size depending on 32bit/64bit memory model and available memory (RAM and swap memory)) because it is allocated from the heap.

    int arraysize= 4200000;
    int *heaparray= new int[arraysize];
    
    ... 
    
    k= heaparray[456];
    
    ...
    
    delete [] heaparray;
    
    return;
    

提交回复
热议问题