I need an algorithm which sorts an array of pairs according to the first element of each pair. The following code works fine for v_size<~2^19, however, at sizes of close to 2^19 it crashes due to a segmentation fault. What is the reason? A size of ~524000 is not huge. (I'm using gcc (Debian 4.7.2-5) 4.7.2)
#include <iostream>
#include <algorithm>
#include <iterator>
#include <time.h>
using namespace std;
int main( int argc, char ** argv )
{
srand(time(NULL));
int v_size=524000;
std::pair<double, int> AB_large[v_size];
for( int i = 0; i<v_size; ++i)
{
AB_large[i].first = static_cast <double> (rand()) / static_cast <double> (RAND_MAX);
AB_large[i].second = i;
}
std::sort(AB_large, AB_large+v_size);
return 0;
}