During some memory tests I did I got a segfault from the following program:
#include <string>
#include <iostream>
using namespace std;
int main()
{
cout << "Beginning Test" << endl;
const int N = 2000000;
string sArray[N];
return 0;
}
Since I got the segfault before "Beginning Test" was printed, I ran it in GDB and checked the backtrace and the only thing I got was:
Program received signal SIGSEGV, Segmentation fault.
0x00000000004008c5 in main () at Main.cxx:11
11 string sArray[N];
(gdb) bt
#0 0x00000000004008c5 in main () at Main.cxx:11
The weirdest thing for me is that if I set N to 1000000 (1M) instead of 2000000 (2M) I don't get the segfault.
Any clue to what the problem might be?
I'm using Linux Red-Hat 2.6.18 and g++ (GCC) 4.1.2.
Thanks!