Object Creation

  • Thread starter Thread starter Ghanta Sunil Krishna
  • Start date Start date
G

Ghanta Sunil Krishna

Hi,

I have a class say...

class A
{
private int i,j,k;
public void m1(){}
public void m2(){}
}
class B:A
{
private int a,b,c;
public void m3(){}
public void m4(){}
}

class C
{
public static void Main()
{
A a1 = new A();
}
}

when i say A a1 = new A() an object of type "A" will
created on the heap the handle to which is assigned to
variable "a1". can anyone give memory layout of this
object.
 
the layout is not documented but here goes

every object (excluding unboxed value types) in memory is preceeded by an
object header - the first field in this is the sync block index and the
second is a handle to a type description structure
(System.RuntimeTypeHandle) this is followed by the objects fields..

the fields of an object may be reorganized to conserve space because of
alignment resttrictions..

you can look at this structure using cordbg and dumping the address for the
object

Also the managed pointer actually points to the type handle and not the
start of the object header...

Being internal details i assume these are subject to change without warning

Rahul

(e-mail address removed)
 
Back
Top