Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

object layout structure in .NET using disassembler

I am interested in seeing the object layout structure, and am trying to use a disassembly in visual studio. Following is my code:

class myclass
{
  public int m_a;
}

myclass myc = new myclass();
myc.m_a = 23;
//I am setting a breakpoint after this line

I opened Memory1 window, and type myc in the Address field. I get the following details int the output window (used Windows XP PC 32bit with Intel compiler):

    0x0148B7BC  1c 93 a7 00 17 00 00 00 00 00 00 00 00 00 00 00 00 00 00

It appears that there is an additional pointer 00a7931c which is added in front of the object data, which increases the object size by 4 bytes. My confusion is that documentation says that object size is increase by 8 bytes due to header per object. Can someone please point me to where the other 4 bytes are?

like image 896
paseena Avatar asked Jan 21 '23 04:01

paseena


1 Answers

From Advanced .Net Debugging - CLR Object’s Internal Structure:

An object’s CLR internal structure is:

[DWORD: SyncBlock][DWORD: MethodTable Pointer][DWORD: Reference type pointer]…[Value of Value Type field]…

Object Header: [DWORD: SyncBlock]
Object Pointer: [DWORD: MethodTable Pointer][DWORD: Reference type pointer]…[Value of Value Type field]…

Every Object is preceded by an ObjHeader (at a negative offset). The ObjHeader has an index to a SyncBlock.

like image 135
dtb Avatar answered Jan 28 '23 07:01

dtb