"virtual memory exhausted: Out of memory" with a large static array

Pavel Saviankou saviankou@web.de
Thu Feb 8 16:21:00 GMT 2007


Hi, 

i would like to compile a programm, which contains an static array with a 
large amount of structures(containts 9 doubles) as elements. I try it on two 
ways. 

One way is: 
I put as an element the structure as 
mystruct array[823543] = { .., { 0.,0.,0.,0.,0.,0.,0.,0.,0.}, ... }
and try to compile.
(Number of elements CAN and WILL be much larger. this is only fewdata test)


First I try the "g++ (GCC) 4.1.2 20070115 (prerelease) (SUSE Linux)" and -O0.
The compilation breaks with  "virtual memory exhausted: Out of memory".
The same result, even if i turn on the optimisation -O1,2,3,4,5 and a lot of 
flags -fxxx .-

Then i try the "g++ (GCC) 3.4.5".
It compiles,  both with -O0 and with -O1,2,3,4,5!

The second way is:
I create 823543 (or even more) structures with the name like struct1, struct2 
and so on

mystruct struct1 = { 0.,0.,0.,0.,0.,0.,0.,0.,0.};
mystruct struct2 = { 0.,0.,0.,0.,0.,0.,0.,0.,0.};
..
and the array with the pointers on they:
mystruct * array[823543] = { &struct1, &struct2, ...};

Now i get the  "virtual memory exhausted: Out of memory" with both versions of 
compiler and with both optimisations settings. 

The source with the structures and array will be generated automatically. 
With a small amount of structures - i have no problems, but i have to have a 
large, more than 100 000 000 numbers of structures, amount of data. 

The same behavior also on 64bits machine (AMD).

How i can get the second variante compuled? 
Or it is a principal problem with the compiler and is unpossible to compile? 

Regards,
Pavel Saviankou



More information about the Gcc-help mailing list