In C++ I am reading in several large gridded datasets for processing. Recently, one of these data sets broke my code before I even got to the processing.
The data set had 5765 cols and 5872 rows for a total of 33852080 cells. Well under the individual vector capacity limit for a double, right? Or not? I'm trying to figure that out currently.
The exception is thrown trying to push_back the inner 2496th vector into the original vectors.
Here's the code:
slopeGrid.reserve(rows);
flowDirGrid.reserve(rows);
flowAccumGrid.reserve(rows);
tempGrid.reserve(rows);
inflowGrid.reserve(rows);
TWIgrid.reserve(rows);
for(int k=0; k<rows; k++)
{
elevation.push_back(*new vector<double>(cols));
ATB.push_back(*new vector<double>(cols));
Area.push_back(*new vector<double>(cols));
slopeGrid.push_back(*new vector<double>(cols));
flowDirGrid.push_back(*new vector<double>(cols));
flowAccumGrid.push_back(*new vector<double>(cols));
tempGrid.push_back(*new vector<double>(cols));
inflowGrid.push_back(*new vector<double>(cols));
TWIgrid.push_back(*new vector<double>(cols));
}