Error 1 error C2148: total size of array must not exceed 0x7fffffff bytes I get this Error in C

-1

I want to make a char[1 048 576][16 384][1024] and a int [1 048 576][16 384] but I get an Error!

I want to make an 3d array as big as excel can handle!

c
arrays
asked on Stack Overflow Jun 12, 2014 by user3724530 • edited Jul 5, 2019 by Cœur

2 Answers

4

to "make" an array in C you need to allocate some memory, either statically or dynamically with malloc. In any case, the array will be mapped physically in your computer like in the RAM. So you need to have enough physical place to "make" it.

In your case, you want a char array of size: 1048576*16384*1024*sizeof(char) = 1048576*16384 MByte with char size is 1 byte.

That is just too much. The error you get is related to that. It tells you that the maximum size you can request is the max number for a signed integer. See: What is the maximum value for an int32?. which is way under what you want to allocate.

If you look at excel, the cells are all empty and no memory is reserved for them until they are filled.

answered on Stack Overflow Jun 12, 2014 by toine • edited May 23, 2017 by Community
3

Unless that array is a global variable, it would be allocated on the stack, whose size is limited (usually, 1MB for VC).

Large objects should be allocated on the heap with malloc. However, such a huge (16TB approximately) object will never fit in the memory of any ordinary device. Chances are that you don't actually need all that memory at once. You should rewrite your algorithm.

answered on Stack Overflow Jun 12, 2014 by Stefano Sanfilippo

User contributions licensed under CC BY-SA 3.0