[Mono-list] mcs compiles on linux. Now what?

Piers Haken piersh@friskit.com
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 [1]. I'm
not sure what Object's GetHashCode() does. I'll look into it. I have a
feeling it's internal, though.

Piers.

[1] Jeffrey Richter's .NET book - you know, the Jeffrey Richter one.
ch.9

-----Original Message-----
From: Paolo Molaro [mailto:lupus@ximian.com]
Sent: Friday, March 08, 2002 3:22 AM
To: mono-list@ximian.com
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
_must_
> 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 courious).

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.

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better

Index: System/Object.cs
===================================================================
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 @@
 		// </summary>
 		public virtual int GetHashCode ()
 		{
-			return 0;
+			return (int)obj_address ();
 		}
 
 		// <summary>

_______________________________________________
Mono-list maillist  -  Mono-list@ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list