title: why g++ compiler use so much memory?
body: <p>I wrote a simplest c++ program in my ubuntu server:</p>
  
  <p>test.cpp:</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  int a[100*100*100*100*10];
  int main() {
      unsigned int count = 0;
      for (int i = 0; i &lt; 100*100*100*100*10; i++) {
          if (i % 10000000 == 0) cout &lt;&lt; i &lt;&lt; endl; 
          a[i] = i;
          count += i; 
      }
      cout &lt;&lt; count &lt;&lt; endl;
  }
  </code></pre>
  
  <p>and my g++ compiler is:</p>
  
  <pre><code>root@ubuntu:~# g++ -v
  Using built-in specs.
  COLLECT_GCC=g++
  COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
  Target: x86_64-linux-gnu
  Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
  Thread model: posix
  gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) 
  </code></pre>
  
  <p>the memory of my server is 64GB.
  when I run <code>g++ test.cpp</code>, it need about 1 minutes to compile this c++ file. and the peak usage of g++ progress is 5GB memory....</p>
  
  <p>why?</p>
  
  <p>by the way, when i run this program, it need about 1minutes to finish.
  I think may be there is something wrong with my memory.
  is it because the memory is too large？</p>