Create too large array in C++, how to solve?

后端 未结 5 1884
感情败类
感情败类 2021-02-03 12:17

Recently, I work in C++ and I have to create a array[60.000][60.000]. However, i cannot create this array because it\'s too large. I tried float **array

5条回答
  •  梦毁少年i
    2021-02-03 12:31

    A matrix of size 60,000 x 60,000 has 3,600,000,000 elements.

    You're using type float so it becomes:

    60,000 x 60,000 * 4 bytes = 14,400,000,000 bytes ~= 13.4 GB
    

    Do you even have that much memory in your machine?


    Note that the issue of stack vs heap doesn't even matter unless you have enough memory to begin with.


    Here's a list of possible problems:

    • You don't have enough memory.
    • If the matrix is declared globally, you'll exceed the maximum size of the binary.
    • If the matrix is declared as a local array, then you will blow your stack.
    • If you're compiling for 32-bit, you have far exceeded the 2GB/4GB addressing limit.

提交回复
热议问题