Jerry
Sun Jun 13 20:56:27 CDT 2004
No problem, I can't imagine the pain of trying to hunt down bugs caused by
the hash code changing...
Jerry
"Randolph Neall" <randolphneall@veracitycomputing.com> wrote in message
news:OPVWUXWUEHA.1284@TK2MSFTNGP10.phx.gbl...
> Hey Jerry,
>
> Can't thank you enough for jumping in here. I've taken your message to
> heart. We could have had some really vile bugs on our hands.
>
> Thanks,
>
> Randy Neall
>
>
> "Jerry Pisk" <jerryiii@hotmail.com> wrote in message
> news:uKKyvP$TEHA.3664@TK2MSFTNGP12.phx.gbl...
>> Inline...
>>
>> "Mattias Sjögren" <mattias.dont.want.spam@mvps.org> wrote in message
>> news:e8W8ca%23TEHA.2028@TK2MSFTNGP11.phx.gbl...
>> >
>> >>can I be sure that the hash of that object will always remain the same
>> >>throughout the life of that object?
>> >
>> > That depends on the implementation of GetHashCode(). For the default
>> > implementation it's true.
>>
>> No it isn't -
>>
>
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemObjectClassGet
> HashCodeTopic.asp.
>> Therefore you can't use the deault GetHashCode implementation for
>> hashing.
>>
>> >>Every reference object has a reference pointer that is, I would guess,
>> >>some
>> >>integer.
>> >
>> > I don't quite understand what you mean here.
>>
>> Not an integer but a pointer.
>>
>> >>If I'm right, that integer is what gets hashed when you make such
>> >>an object a key in a hash table.
>> >
>> > Any data can be used to derive the hash. Again, it depends on the
>> > GetHashCode() implementation.
>>
>> Randolph is right and you can't use that for hashing. You have to
> implement
>> your own GetHashCode that will return the same value for a single object,
> no
>> matter what happens to that object.
>>
>> >>or does garbage collection cause a change in this integer
>> >
>> > I don't think garbage collection could ever change the hash. But
>> > making mutating changes to the object could.
>>
>> Yes it does, for the default Object.GetHashCode implementation it does.
> Once
>> again, DO NOT USE IT in hash tables.
>>
>> > Mattias
>> >
>> > --
>> > Mattias Sjögren [MVP] mattias @ mvps.org
>> >
http://www.msjogren.net/dotnet/ |
http://www.dotnetinterop.com
>> > Please reply only to the newsgroup.
>>
>>
>
>