[Mono-dev] GetHashCode() implementation for class string

CarGa carga at mail.ru
Mon Dec 1 16:44:21 EST 2008


Hello, all!

I was directed here by Atsushi Eno from mono-olive list with this question/request about GetHashCode() method.

DependencyProperty class (that lays at the very base of entire WWF and WPF libraries) heavily depends on quality of GetHashCode() method since we use it to find any particular DependencyProperty in some huge Dictionary<int, DependencyProperty> of others.

Small test shows, that there are HUGE amount of 2, 3 and 4 letter strings that have the same hash. I tested this with fresh mono built from SVN and I found thousands of words (quite short in fact) that have the same hash. For example

Pattern 'gCat' has the same hash 3135983 as 'fbbU'
Pattern 'gCc6' has the same hash 3135983 as 'gCat'
Pattern 'gCbU' has the same hash 3135983 as 'gCat'
Pattern 'gDD6' has the same hash 3135983 as 'gCat'
Pattern 'gDBt' has the same hash 3135983 as 'gCat'
Pattern 'gDCU' has the same hash 3135983 as 'gCat'
Pattern 'fbc6' has the same hash 3135983 as 'gCat'
Pattern 'fbat' has the same hash 3135983 as 'gCat'
Pattern 'fbbU' has the same hash 3135983 as 'gCat'
Pattern 'fcD6' has the same hash 3135983 as 'gCat'
Pattern 'fcBt' has the same hash 3135983 as 'gCat'
Pattern 'fcCU' has the same hash 3135983 as 'gCat'

About 700 MBytes of wrong matches for words from 1 to 7 characters with alphanumeric alphabet of 63 symbols.

This fact may lead to unpredictable and ununderstandable failures not only for WWF and WPF (we can rewrite our searching at the end), but to any application that is being ported to mono.

There is also at least one blog in Net which points attention to this fact. Do YOU know about the issue? Do you plan to fix it?



And one more. =) I tried to write some system statistics to console. Total memory, total available memory, total virtual memory and used physical and virtual memory. But the only answear was 0 bytes. I have heard, that Mono v2.0 is completely compatible with Framework 2.0 and that it implements every of Ms classes and methods... But this is not true, isn't it? I have to know for myself to be sure when we argue with guys about different OSes for "true-developers". =)

Here is the snippet:

var currentProcess = System.Diagnostics.Process.GetCurrentProcess();
Console.WriteLine ("\tPrivate Memory Size: " + currentProcess.PrivateMemorySize64);
Console.WriteLine ("\tPaged Memory Size: " + currentProcess.PagedMemorySize64);
Console.WriteLine ("\tVirtual Memory Size: " + currentProcess.VirtualMemorySize64);
Console.WriteLine ("\tWorking Set: " + currentProcess.WorkingSet64);

Is it possible to return correct memory size? I have 8 GB of physical memory and about 32 GB of swap partition. I am very interested to measure the memory limits of my program before OS will terminate the process. =)

Best regards,
Anton.


More information about the Mono-devel-list mailing list