When to use a HybridDictionary over other Dictionary types?
I am looking at the Collection classes in MSDN for the .Net framework. I
ran into the HybridDictionary and it states
(http://msdn.microsoft.com/en-us/library/system.collections.specialized.hybriddictionary.aspx):
Implements IDictionary by using a ListDictionary while the collection is
small, and then switching to a Hashtable when the collection gets large.
So I wondered about the ListDictionary which states
(http://msdn.microsoft.com/en-us/library/system.collections.specialized.listdictionary.aspx)
Recommended for collections that typically include fewer than 10 items.
Now that seems like an arbitrary number (of items) to me. I can't find in
the documentation what the mechanism behind this would be, I suspected the
boundary of performance would have been related to a number of items like
2^N (2 to the power of N).
Now I do use the collection type of Dictionary often, and the collections
might contain 10 to 30 items, 50 tops, depending on the 'page size'.
But HybridDictionary and ListDictionary requires unboxing and there are no
generic type contructors for them.
I can't find a comparison anywhere about the performance of a
HybridDictionary vs Dictionary.
So when to actually use this HybridDictionary over other Dictonary types?
P.S. And if HybridDictionary switches to ListDictionary or HashTable when
the number of items grow to optimize its functioning. Why ever use a
ListDictionary? If some requirements in the software change, and suddenly
a maximum of 20 items must be put in the ListDictionary, instead of a
maximum number of 10 items, the code must be re-factored to HashTable to
maintain performance?
No comments:
Post a Comment