ultr wrote:
I need a large 3D array of structures:
struct s {
char a[40];
int b;
};
s s_array[10000][10000][100];
s_array is declared as global.
Unfortunatelly, when compiling, I get an error: "size of array
's_array' is too large"
(using GCC, but I think it doesn't matter)
But I have read, that global variables can be very large. Is it true?
And how can I make it in other way?
You can allocate static storage for variables, and it can generally be
larger since it's not allocated <ot>on the stack</ot> like automatic
variables. You could also use dynamic memory allocation (new/delete or
malloc/free) to achieve the same goal.
However, your array *is* very large, and on a typical 32-bit system it
would be (10^10)*(40+4) = 440000000000 = 0x66720B3000 which is well
beyond 32-bit pointer ranges. (Are you writing exclusively for 64-bit
machines or better?)
You could solve this problem in any number of ways. One is to access
the array in chunks so you only use part of that memory at any one
time. Another would be to break up your array behind some abstraction.
Etc. Etc. Give us a better idea of what you're doing, and perhaps we
can make some better suggestions.
Cheers! --M