CLR 依情境以兩種方式配置實值型別實例:
public class Test1 {
private int i; // (2) 欄位:隨 Test1 實例在 GC Heap 配置
public Test1() {
byte b = 0; // (1) 區域變數:在執行緒堆疊配置
}
}
依物件大小分流:
public class Test2 {
private int[] intArr;
public Test2() {
object o = new Object(); // 參考 o 在堆疊,實例在 GC Heap
intArr = new int[21250]; // 21250 * 4 bytes = 85,000 bytes → LOH
}
}
Test2.intArr)object o)this 指標、fastcall 傳遞參數(ECX/EDX)示意圖:

物件參考指向 Object Header (4 bytes) 之後:
SyncTableEntry,含鎖、雜湊碼、AppDomain 索引等。未使用時為 0;lock(obj) 或 GetHashCode() 觸發配置。MethodTable(類似 C++ vtable 但更複雜)。StructLayoutAttribute(LayoutKind.Auto) 自動排序以節省空間,順序不一定與宣告順序相同。Object obj = new Object(); // syncblk = 0
lock(obj) { /* ... */ } // CLR 建立 SyncBlock,更新 Object Header
obj.GetHashCode(); // 同步區塊記錄雜湊碼