When I do:
public class Employee
public int exp;
static void Main(string args)
Employee o1 = new Employee();
o1.exp = 3;
//I am here
and get memory of o1 (address is 0x022cf940):
I realized couple of things mentioned below:
- Green rectangle is sync block, which is 12
- Blue rectangle is 4 byte address of type
- Red rectangle is 4 byte integer, which is 3;
Question: Where is the space of sync blocks and how can I find it? What does "12" stand for?
Best How To :
The sync block has more than one use. It can store the value of Object.GetHashCode() so that an object always returns the same hash code when GetHashCode() is called again. It can store the ID of the owner thread of a lock statement. It has several dedicated bits, like indicating that the finalizer for an object has been run. And it can store a handle to an allocated sync block, necessary when a thread both called GetHashCode and used lock and the info can't fit in the sync block anymore. It is very heavily micro-optimized.
Your case is the simple case, only lock was called and none of the dedicated bits are turned on. So you see the owner of the lock, 0x12 = 18 is the Thread.ManagedThreadId of the thread that owns the lock. That can come in pretty doggone handy when you ever need to troubleshoot a deadlock.
You can make the debugger display a bit easier to interpret when you right-click the window and select "4-byte Integer". The green rectangle is the method table pointer for the object (aka "type handle"). It indicates the type of the object, Object.GetType() uses it. The red rectangle is where the object starts storing its fields. Since yours only has the
exp field and its type is Int32, you can see 3 back.