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

后端 未结 5 1881
感情败类
感情败类 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条回答
  •  北荒
    北荒 (楼主)
    2021-02-03 12:56

    Allocate the memory at runtime -- consider using a memory mapped file as the backing. Like everyone says, 14 gigs is a lot of memory. But it's not unreasonable to find a computer with 14GB of memory, nor is it unreasonable to page the memory as necessary.

    With a matrix of this size, you will likely become very curious about memory access performance. Remember to consider the cache grain of your target architecture and if your target has a TLB you may be able to use larger pages to relieve some TLB pressure. Then again, if you don't have enough memory you'll likely care only about how fast your storage I/O is.

    If it's not already obvious, you'll need an architecture that supports a 64-bit address space in order to access this memory directly/conveniently.

提交回复
热议问题