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:
Post a Comment