I have a question involving memory allocation. Let's say I create an array of pointers like this.
int **numbers = new int *[1024*1024];
I had assumed that this would need 8MB of memory (8-byte pointer on Mac 64-bit) but that's not the case. Memory is only allocated when each pointer is assigned a value. So if I NULL all the pointers then I see 8MB being allocated.
for(int i=0; i<1024*1024; i++)
{
numbers[i] = NULL;
}
How does my app know which pointers have an assigned a value without allocating memory for it?