-2

I am making a C# application which contains hundreds of classes for my SDK. I need to store the managed objects of that classes in my C# Dictionary. But I dont know how much objects that dictionary could hold?Meaning will it be a good feasible solution to all the objects with a integer key associated with it? If there is another way, I'm welcome to those ideas.

  • Local Database, like SQLite could be a better way if you run out of memory. – jAC Jun 07 '13 at 13:36
  • If you don't know, test it out. If you run into performance issues or out of memory go for a local storage. – Alex Jun 07 '13 at 13:37
  • Have you researched the capacity of a C# dictionary? – Big Daddy Jun 07 '13 at 13:38
  • When you say `managed objects of that classes` do you mean in like lifetime management of object instances as in Inversion of Control containers? – Quinton Bernhardt Jun 07 '13 at 13:42
  • 1
    @Quinton Bernhardt: He's probably referring to [objects whose memory is managed by the .NET GC](http://stackoverflow.com/questions/3607213/what-is-meant-by-managed-vs-unmanaged-resources-in-net). – jason Jun 07 '13 at 13:43

2 Answers2

3

If your keys are integers, you're limited by the total number of keys being equal to the total number of values of Int32, and by the limit on memory consumed by a .NET process. Of course, you could run out of "capacity" well before that depending on the rest of your system. You'll have to test exactly what those limits are in real use cases for your application, because we don't know the size of your objects, or the load on your application, etc.

You should strongly consider local storage, even something like SQLite if you're worried about not having enough memory.

jason
  • 236,483
  • 35
  • 423
  • 525
0

The Dictionary class has an upper limit of 2^31 items, if you're running .NET 4.5 on a 64-bit platform and use the <gcAllowVeryLargeObjects> element.

If you don't enable gcAllowVeryLargeObjects, and for earlier versions of .NET, the number of items you can store in the dictionary is somewhat smaller. With an Int32 key and a reference type for the value, a Dictionary can hold a maximum of about 89.4 million items on the 64-bit platform, and 61.7 million items on the 32-bit platform. Assuming, of course, that you have enough memory to hold the dictionary and the values.

See my article about dictionary limits at http://www.informit.com/guides/content.aspx?g=dotnet&seqNum=665

Jim Mischel
  • 131,090
  • 20
  • 188
  • 351