This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: "virtual memory exhausted: Out of memory" with a large static array
- From: Andrew Haley <aph at redhat dot com>
- To: Pavel Saviankou <saviankou at web dot de>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Thu, 8 Feb 2007 16:24:32 +0000
- Subject: Re: "virtual memory exhausted: Out of memory" with a large static array
- References: <200702081630.24778.saviankou@web.de>
Pavel Saviankou writes:
> 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.
This will indeed run out of memory during compilation. Why not read
the data into your array at runtime?
Andrew.