Friday, September 17, 2004

More on HashCode...

Continuing to my previous post, I was wondering how this HashCode is calculated. On what basis this hashcode is returned.
Here are my conclusions::
Object.GetHashCode returns an index to an internal SyncBlock table that CLR maintains for object synchronization. Each element of this internal table is reference of the SyncBlock for an object.
Also I gave some logical reasons why we get a duplicate HashCode. After knowing how the HashCode is calculated, I deduced that when the object is alive in memory, HashCode functions returns the index of the internal table where the SyncBlock reference is stored. Now when the object is dead or is not in memory any more, this table entry gets empty or null. When new object is created, its SyncBlock reference is also needed to be stored in this table. System might use the same table entry to store the SyncBlock reference for this new object. This is the reason why we get duplicate HashCode for different objects.


Post a Comment

<< Home