Why is it that when compiling Sample 1
, it uses all my RAM and crashes my computer yet Sample 2
compiles instantly without doing so?
Sample 1:
class Foo
{
int a = 0;
};
class Test
{
Foo foo[4000000] = {};
};
int main()
{
Test t;
}
Sample 2:
class Foo
{
int a = 0;
};
int main()
{
Foo foo[4000000] = {};
}
Lastly, is there any way to stop Sample 1 from using tons of RAM when compiling? I'm using gcc version 5.3.0
and I compiled the above with -std=c++11
. Note that class Test
should only require a mere 16 MB of memory.
For any