Is there any Alternative of Dictionary<Key, Value> with non contiguous memory allocation in C#

149 Views Asked by At

Using Dictionary<Key, Value> causing issues in memory allowing ( error Failed to allocate memory) in the application So is there any alternative which is allocate memory in non contiguous form.

I tried with sortedList<Key, Value> collection but doesn’t work out

1

There are 1 best solutions below

0
gterdem On

Memory allocation will be based on the objects you add to the dictionary (or HashSet or SortedList, or any kind of list).

If you want to keep fixed sized of items in your dictionary, you can pass the capacity for the dictionary when instantiating it. Or you can use Stack<TItem> with capacity so you can push/pop.