i am trying to fill a two dimensional vector(817 by 577) with objects called cells. These cells have a set of member values (floats, other vectors etc). At a certain point the program stops and throws the error "vector<T> too long"
.
Here is the class definition of cells and the complete loop:
struct cell
{
int x;
int y;
int country;
vector<int> popO;
vector<int> popS;
vector<float> Rainfall;
double Cropland;
vector<movement> outm;
vector<movement> inm;
vector<double> AgeMaleFemale;
vector<double> AgeMaleFemaleMortality;
double Fertility;
};
vector<vector<cell>> cells;
void fillCells(dataserver D)
{
cout<<"start filling"<<endl;
int rows=577;
int columns=817;
cell X;
vector<vector<cell>> output(rows,vector<cell>(columns,X));
cout<<"start loop"<<endl;
for (int i=0;i<rows;i++)
{
cout<<i<<" ";
for (int j=0;j<columns;j++)
{
int p=-9999;
cell tmpC;
tmpC.x=i;
tmpC.y=j;
tmpC.country=D.CO[i][j];
tmpC.popO.resize(3,0);
tmpC.popO[0]=int(D.PO[0][i][j]);
tmpC.popO[1]=int(D.PO[1][i][j]);
tmpC.popO[2]=int(D.PO[2][i][j]);
tmpC.Rainfall.resize(10,0);
for (int k=0;k<10;k++)
{
tmpC.Rainfall[k]=D.R[k][i][j];
}
tmpC.popS.resize(10,0);
tmpC.Cropland=D.CPC[i][i];
if (tmpC.country!=-9999)
{
tmpC.Fertility=D.F[tmpC.country];
tmpC.AgeMaleFemale.resize(18,0);
tmpC.AgeMaleFemale=D.AMF[tmpC.country];
tmpC.AgeMaleFemaleMortality.resize(18,0);
tmpC.AgeMaleFemaleMortality=D.M[tmpC.country];
}
output[i][j]=tmpC;
}
}
cells=output;
}
Googling a bit I found out that sizeof(cell) times the number of cells in the vector is supposed to smaller than vector::max_size()
sizeof(cell) is 144 ->144*817*577=67882896
max_size is 268345455
Shouldn't there be enough space for all the cells then, or am I missing something? Thanks in advance!
Some additional Info:
Running on Windows 7 64bit, compiling with Visual Studio 2010, 32 bit
The info about max_size actually came from here: stl "vector<T> too long"