The topics described here concentrates fully on pure .Net Framework, describing actual meaning of some programming concepts, FCL and best practices. However you will be using these concepts in all . Net framework compatible languages like Microsoft visual basic .net (VB.Net) or C# .Net (csharp.Net) to build a web application (Asp.Net) or Desktop applications (winforms .net) or Web/Windows services





This blog has moved!

You will be automatically redirected to the new address. If that does not occur, visit
http://Codemine.net
and update your bookmarks.

Wednesday, June 20, 2007

A sneak look into Object

In .NET, each heap-allocated object consists of a 4 byte objectheader and 4 byte pointer to a method table, may be called as MethodTablePointer and contains the memory address to the type's method table. Basically, this pointer makes it possible to obtain the type information about any object in the heap as and when you call System.Object’s GetType () method.
The 4 byte objectheader provides five bit flags, one of which is reserved for the garbage collector to mark an object as reachable/unreachable and whether to free or not free the space allocated by that object. The remaining bits refer to a 27 bit index called a syncindex or SyncBlockIndex, which may refer to another table. This index has multiple purposes: As implied by its name it is used for synchronization, whenever the "lock" keyword is used. It is also used as the default hash code for Object.GetHashCode (). It does not provide the best distribution properties for a hash code, but it meets the minimum requirements for a hash code for reference equality.
The syncindex remains constant throughout the life of the object. But we cannot assure that the integer values from Object.GetHashCode () will be unique. The string class overrides this method to take care of the object equality, that’s why the identical string objects are returning the same hash code. And also we are able to use the EQUALS method to compare between two string objects. So whenever you are overriding the EQUALS method you have to override the GetHashCode () also and vise versa in order to bring out a proper meaning while using the EQUALS method.
In future i think that i can find more about these things. so this is only an initial post

0 comments: