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

前端 未结 4 926
时光说笑
时光说笑 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:08

    I want to create an array

    Do you really need an array? In other words, do you require your integers to be in one memory block, or you simply want to access them by index? If you don't care about the memory layout, but still want to have fast access to elements, you should use std::deque. Instead of allocating one chunk of memory, it'll store your numbers in many small chunks, so as long as you have enough memory to store all your numbers together, you'll be fine.

提交回复
热议问题