I wrote a very small program:
#include <array>
#include <tuple>
#include <iostream>
const unsigned int NUM = 500;
void simple()
{
using namespace std;
array<tuple<float, float, float>, NUM> vectors;
}
int main(int argc, char **argv)
{
std::cout << "Hello, world!" << std::endl;
return 0;
}
I compiled it with g++ -std=c++0x
.
This version works just fine, but if I increase NUM
to maybe 50,000,000, g++ uses 90% CPU and my system freezes entirely.
I understand that a program can crash during execution if there is not enough stack memory. But why would the compiler freeze during compilation?
Is this a bug in g++ or does the compiler need to allocate stack memory during compilation for some reason?