Array with Pointer

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

Hi, the following code cause a StackOverflowException. Can someone tell me
why?


Thanks
Tony



///////////////////////////////////////////////////////////////////

using System;

namespace UnsafeArrayTest
{
class Class1
{
unsafe static void Main(string[] args)
{
int size = 999999;

int *pArray = stackalloc int [size]; // << StackOverflowException

for ( int i = 0; i < size; i++ )
pArray = i;

}
}
}
 
Hi, the following code cause a StackOverflowException. Can someone tell me
why?

Because the stack isn't big enough to hold the 4*999999 bytes you're
trying to allocate from it.



Mattias
 
Back
Top