Understanding CLR object size between 32 bit vs 64 bit

后端 未结 4 857
旧时难觅i
旧时难觅i 2020-12-14 09:44

I am trying to understand the object size difference between 32 bit and 64 bit processors. Let’s say I have a simple class

class MyClass   
{  
    int x;          


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-14 10:23

    The sync block sits at a negative offset from the object pointer. The first field at offset 0 is the method table pointer, 8 bytes on x64. So on x86 it is SB + MT + X + Y = 4 + 4 + 4 + 4 = 16 bytes. The sync block index is still 4 bytes in x64. But the object header also participates in the garbage collected heap, acting as a node in a linked list after it is released. That requires a back and a forward pointer, each 8 bytes in x64, thus requiring 8 bytes before the object pointer. 8 + 8 + 4 + 4 = 24 bytes.

提交回复
热议问题