Memory

  • Thread starter Thread starter J. Marcelo Barbieri
  • Start date Start date
J

J. Marcelo Barbieri

In the following array instantiation, what will be the memory space
allocated in the Heap?

object[] myarray = new object[10];



thanks a lot.
 
An array keeps internal pointers to the objects (implicit in C#), unless
it's an array of reference types. Each pointer has a system-defined length,
which on most systems is four bytes. So this array would take up 40 bytes
plus whatever other header information the Array class stores in memory. If
you assign a value type to one of your myarray elements, the value would be
"boxed", which means a pointer to it would be stored so it could be treated
like a refence type as long as you treat it like an object.

Chris
 

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