Saturday, November 6, 2010

long long int a[1000000000] !!!

So today when i was coding for a problem on a website, I encountered an error by declaring
long long int a[1000000000];
I was compiling through C++(4.3.2)..
and the error was  size of array 'a' is too large 
Now the thing is "long long int"is like  8 bytes and 10^9*8 is nearly equal to 8GB and this space couldn't be allocated by compiler..the funda behind it is that the memory allocated by a compiler is allocated on either stack or heap..Whenever we allocate on heap then it depends on the memory we have and in case of stack it depends on size of STACK FRAME..so the above declaration tries to allocate memory on stack but its size is insufficient to handle it..