I am looking into the code behind Dictionary<TKey, TValue>
. What is interesting is in the private Insert
method, there is a bucket
that appears to be holding empty slots in a pre-sized array. Inside the Insert
method, the code checks to see if the bucket has any elements left and will resize if necessary. The number of elements added is a factor of a prime number. Also, dictionary entry properties are stored in a struct with hashcode, key, and value.
My question: what is the purpose? Is this done to prevent trying to add items to the dictionary object when sufficient memory might not be available?
NOTE: I didn't want to paste any of the code here since it requires disassembling to read.