I have the following code:
int main() {
int N = 1000000;
int D = 1;
double **POINTS = new double * [N];
for (unsigned i=0;i<=N-1;i++) POINTS[i] = new double [D];
for (unsigned j=0;j<=D-1;j++) POINTS[0][j] = 0;
for (int i = 0; i < N; ++i)
{
for (int j = 0; j < D; ++j)
{
POINTS[i][j] = 3.14;
}
}
}
If the size of each pointer
is 8
and N = 10^6
and D = 1
, it is expected that size of POINTS
must be 8 * 10^6 * 1 / 1000 / 1000 = 8 mb
but in fact this program eats 42 mb
of memory. If N = 2 * 10^6
it is expected 16 mb
but actually 84
. Why?