One thing that you can do only with a reference type

What in your opinion possible to do only with reference type and no with value type without explicit boxing?

What the fact of derived from object that give all reference type some ability that value types don’t have?

You can say ToString method or GetHashCode or Equals or GetType but you actually know that you can do it also with value type via implicit boxing.

So maybe the ability to pass by reference? Also no. you can use the c# ref or out to pass value type by ref.

What about store value types on the heap? It’s not the programmer business at all where the memory allocated but anyway value types can be in the heap (actually most of your value type memory exist in the heap…)

So what I mean is of course using lock (Monitor). You can do it only with reference type and this is because the SyncBlock. (object header)

The SyncBlock is a four bytes that holds an index into SyncTableEntry table, that table contains several things like ComData, AppDomainID, Hashcode and Monitor.

Every time you do:

lock(myObject);

The SyncBlock structure is initialized and the object SyncBlock get an index to the table that contains the data.

When your thread blocked and wait there is an event handle associate with his SyncBlock and that why the SyncBlock is needed.

Advertisements
This entry was posted in .NET and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s