Dictionary<K, V> will automatically resize when needed. Presumably, the Capacity values it uses are in monotically increasing values determined by some algorithm, and thus one can assume that all dictionaries size up on these boundaries. Our system
uses lots of Dictionaries, some of which get quite large and end up in the Large Object Heap. But because they all currently grow from 0, I assume (based on memory profiling) that I am allocating always exact sized chunks from LOH. so in practice, this never
leads to a seriously fragmented LOH because all the allocated blocks are exact even multiples of some basic value.
I want to enhance the system by using the initial Capacity constructor based on an estimated capacity. But my big worry is that it will allocate that exact amount, and that this will therefore lead to serious fragmentation of the heap. List<V> provides
an explicit Capacity property, so I could experiment with that collection to determine its behavior, but Dictionary does not provide any access to its current capacity. Does anyone know about this? Basically I want to know if when I request the initial Capacity
in the ctor, will it actually round that up to one of its magic values that I would have hit had I increased its contents one by one; or is it going to just request that exact amount of capacity?
View Complete Post