Creating a large array of numbers (10^9 size)

前端 未结 4 922
时光说笑
时光说笑 2020-12-16 02:32

I want to create an array that is capable of storing 10^9 numbers(long int).If i try doing this my compiler crashes.What is the maximum size array allowed in C++.Also if i d

4条回答
  •  无人及你
    2020-12-16 03:14

    An array of 10^9 longs would typically take up at least 4GB of memory, which would already be prohibitive in all 32-bit systems.

    Even if that much memory is available in a 64-bit system you certainly cannot expect to allocate 4GB on the stack like this:

    void foo() {
        long arr[1000000000]; // stack size is a typically few MBs!
    }
    

提交回复
热议问题