Reputation: 49
I was wondering if having lots of small Dictionary wastes memory because of the overhead involved. Dictionary is implemented as a hash table, so if I have thousands of objects that each contain these small dictionaries don't I end up wasting a lot of space as opposed to just having a list/binary search tree that I search through, especially if each small dictionary only contains 4-5 key value pairs?
The code I am looking at now is implemented like that, and since there are memory issues I was wondering how wasteful it is to use hash tables for small number of items. What are my other options besides list/binary search trees?
Upvotes: 3
Views: 1220
Reputation: 1497
if you need the hashing functionality you could use a hastable instead of a dictionary, if not some lightweight collection will do. you can check out this link Dictionary vs Hashtable memory usage
Upvotes: 1
Reputation: 12164
Benchmarking is the best way to see performance vs. memory issues, of course, but if each dictionary will be that small, consider the ListDictionary or HybridDictionary classes. For small dictionaries you should definitely see a performance benefit and I suspect you will see a size benefit as well.
Upvotes: 1