简体   繁体   中英

Runtime error with 2d Array “std::bad_alloc()” what()

I have dynamically allocated a 2D array of size 1100*10^9 and I am getting the following runtime error -

This is the runtime error

I don't encounter this error if I decrease the size of the array to 1100*10^5 . Please Help . Thanks in advance . Edit - I have added the part where I allocate the array.

 unsigned int** cache = new unsigned int*[1100] ;
for (int i = 0 ; i < 1100 ; i++)
    cache[i] = new unsigned int [1000000000] ;

1100 * 10^9 is 1.1*10^12 elements. Let's for a moment assume that these elements are 4-byte integers, that's a total allocation of:

4.4 * 10^12 bytes

dividing by 1024 * 1024 * 1024 to get gigabytes...

1,048,017.748 GB - which is about a thousand terabytes.

I don't think there is a processor architecture anywhere on the planet which can address, let alone allocate, this much ram.

(although if I'm wrong about this I'd be fascinated to hear it!)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM