I am struggling with strange result for basic program.
I checked tutorialspoint site and it says unsigned long is 8byte.
I am multiplying unsigned long and unsigned int.
And it seems that multiplying result does not exceeds the maximum value of unsigned long(18,446,744,073,709,551,615). But I get 56557 instead of 85,899,402,477.
I tried also
unsigned long gridTotalSize = (unsigned long)xGrids * yGrids;
but the same result.
I wanted to limit the memory allocation capacity by this multiplying value.
unsigned long gridTotalSize = ((unsigned long )xGrids) * yGrids;
if (gridTotalSize == 1)
{
return false;
}
else if (gridTotalSize > 1000000)
{
return false;
}
But because gridTotalSize = 56557, it passes this size limit check, and tries to allocate 85,899,402,477 bytes, this is nearly 85GB, and very frustrating. Every time I debug, I should press power off button and restart computer for completely stuck from memory overflow.
std::vector<Row> rows;
rows.resize(yGrids); //111,321
for (Row& row : rows)
{
row.resize(xGrids); //771,637
}
I am wasting so many time for this. Any help will be really appreciated.