[Mono-list] mcs compiles on linux. Now what?
Fri, 8 Mar 2002 05:39:53 -0800
yup, the pointer will definitely work, until it changes, of cource
changing it is easier said than done, right? ;-)
microsoft's implementation of ValueType.GetHashCode() basically uses
reflection to find the first non-zero field and returns that . I'm
not sure what Object's GetHashCode() does. I'll look into it. I have a
feeling it's internal, though.
 Jeffrey Richter's .NET book - you know, the Jeffrey Richter one.
From: Paolo Molaro [mailto:firstname.lastname@example.org]
Sent: Friday, March 08, 2002 3:22 AM
Subject: Re: [Mono-list] mcs compiles on linux. Now what?
On 03/07/02 Piers Haken wrote:
> Yes, Object.GetHashCode() must be based on immutable instance values
> (otherwise you lose objects in hashtables). But the kicker is that if
> Object.Equals() returns true then the two object's GetHashCode()s
> be the same !!!
I now remember I saw that discussion. The hack I used yesterday was to
use the address of the object as the hash key: this works nicely for
class types until we have a moving garbage collector:-)
I planned to write a proper solution today, but since there are issues
on what the 'proper solution' could be, I'm keeping my current hack
without committing it to cvs (it's included at the end of the mail for
The right solution should probably involve calculating the hash only
over valuetype fields in the object, skipping object references (that
can vary with a moving collector). This could be the default behaviour,
more complicated stuff must be handled on a per-type basis.
email@example.com Monkeys do it better
RCS file: /cvs/public/mcs/class/corlib/System/Object.cs,v
retrieving revision 1.13
diff -u -r1.13 Object.cs
--- System/Object.cs 2002/03/07 22:59:52 1.13
+++ System/Object.cs 2002/03/08 07:25:51
@@ -63,7 +63,7 @@
public virtual int GetHashCode ()
- return 0;
+ return (int)obj_address ();
Mono-list maillist - Monofirstname.lastname@example.org