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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top