Extreme memory usage with large object arrays

Why does it use all my RAM when compiling Sample 1 does my computer crash yet Sample 2 compiles instantly without doing this?

Example 1:

 class Foo { int a = 0; }; class Test { Foo foo[4000000] = {}; }; int main() { Test t; } 

Example 2:

 class Foo { int a = 0; }; int main() { Foo foo[4000000] = {}; } 

Finally, is there a way to stop fetching 1 using tons of RAM when compiling? I am using gcc version 5.3.0 and I compiled above using -std=c++11 . Note that class Test should only require 16 MB of memory.

For anyone

+5
source share
1 answer

This is definitely a mistake. I can reproduce this with 5.3 on my system. RAM usage is increasing rapidly, but I closed the program because I do not want my system to crash. On the other hand, if I compile it in Clang 3.8, it compiles almost instantly.

I suggest reporting this to gcc.gnu.org/bugzilla. As indicated here, view error reports 59659, 68203, and 56671. I am sure that they all point to the same problem as GCC's inability to have a large array of non-trivial class type.

-2
source

All Articles