Using Dictionary Using Hashtable Memory

I read here at SO that Hashtable and Dictionary are pretty much the same, with the exception of the benefits of avoiding boxing / unboxing.

Using Ants Profiler I am measuring a very simple application with the following structures:

class Node { Dictionary<string, Node> Children = new Dictionary<string, Node>(); } 

and

  class NodeOld { Hashtable Children = new Hashtable(); } 

Well, a list of 1.5 million copies of the first takes about 140 MB, and the second - more than 700 MB (64 bits).

So, there is a huge difference in implementation, right?

Ants Profiler presents a huge number of Hashtable + Bucket objects using a large example ...

So, is there an equivalent (savvy memory) option for dictionaries if you have to adhere to 1.1?

+6
source share
1 answer

Even if I was stuck on .NET 1.1, I would not keep in memory 1.5 million copies, so I would not care. A hashtable is probably the best data structure that implements a hash table that you can get in terms of consumption and memory speed in .NET 1.1. Of course, if you explain your scenario in more detail and make sure that the Hashtable is actually the bottleneck for your application, there may be some more efficient solutions.

+1
source

Source: https://habr.com/ru/post/893019/


All Articles