473,426 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 software developers and data experts.

C# DIctionary size limit

Hi Guys,

I have a class A composed of several string and int members.
I would like to manage a huge amount (several thousands) of A objects
in a dictionary where each object has its unique key.

Is there any known limitation or best practice that you think I should
consider?

Thanks,
Orsula.z
Aug 12 '08 #1
10 23688
On Aug 12, 4:53*pm, orsula <orsul...@gmail.comwrote:
I have a class A composed of several string and int members.
I would like to manage a huge amount (several thousands) of A objects
in a dictionary where each object has its unique key.

Is there any known limitation or best practice that you think I should
consider?
"Several thousand" is actually reasonably small. Basically if you've
got enough room in memory for the objects and a bit of overhead, the
dictionary should be fine.

Jon
Aug 12 '08 #2
Orsula,

Be aware that as with every system collection, you are only adding the
references of the objects, not the values itself, therefore a dictionary can
be in fact very small.

Cor

"orsula" <or******@gmail.comschreef in bericht
news:59**********************************@k13g2000 hse.googlegroups.com...
Hi Guys,

I have a class A composed of several string and int members.
I would like to manage a huge amount (several thousands) of A objects
in a dictionary where each object has its unique key.

Is there any known limitation or best practice that you think I should
consider?

Thanks,
Orsula.z
Aug 12 '08 #3
On Aug 12, 7:11*pm, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Aug 12, 4:53*pm, orsula <orsul...@gmail.comwrote:
I have a class A composed of several string and int members.
I would like to manage a huge amount (several thousands) of A objects
in a dictionary where each object has its unique key.
Is there any known limitation or best practice that you think I should
consider?

"Several thousand" is actually reasonably small. Basically if you've
got enough room in memory for the objects and a bit of overhead, the
dictionary should be fine.

Jon
Thanks (again :) ) Jon
Aug 12 '08 #4
orsula wrote:
I have a class A composed of several string and int members.
I would like to manage a huge amount (several thousands) of A objects
in a dictionary where each object has its unique key.

Is there any known limitation or best practice that you think I should
consider?
No.

My understanding is that would be able to stuff 2GB/16B = 125 million
of entries in a Dictionary<string,Aon 32 bit Windows.

Arne
Aug 13 '08 #5
On Aug 13, 1:21*am, Arne Vajhøj <a...@vajhoej.dkwrote:
No.

My understanding is that would be able to stuff 2GB/16B = 125 million
of entries in a Dictionary<string,Aon 32 bit Windows.
Not quite. For one thing I think there's an upper limit of about 1GB
per object (including the entries array) in the CLR. I've also found
that for some reason (using a Dictionary<int,intto avoid creating
any extra objects) the memory per entry averages at around 40 bytes
rather than 16. No idea why at the moment - 16 would make sense to me
as well, although there's bound to be *some* extra overhead for the
buckets etc. Possibly alignment issues? Hmm...

Jon
Aug 13 '08 #6
A little bit difficult, because then all pairs should be referencing to null
and that is not possible.

Cor

"Arne Vajhøj" <ar**@vajhoej.dkschreef in bericht
news:48***********************@news.sunsite.dk...
orsula wrote:
>I have a class A composed of several string and int members.
I would like to manage a huge amount (several thousands) of A objects
in a dictionary where each object has its unique key.

Is there any known limitation or best practice that you think I should
consider?

No.

My understanding is that would be able to stuff 2GB/16B = 125 million
of entries in a Dictionary<string,Aon 32 bit Windows.

Arne

Aug 13 '08 #7
On Aug 13, 1:18*am, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
On Aug 13, 1:21*am, Arne Vajhøj <a...@vajhoej.dkwrote:
No.
My understanding is that would be able to stuff 2GB/16B = 125 million
of entries in a Dictionary<string,Aon 32 bit Windows.

Not quite. For one thing I think there's an upper limit of about 1GB
per object (including the entries array) in the CLR. I've also found
that for some reason (using a Dictionary<int,intto avoid creating
any extra objects) the memory per entry averages at around 40 bytes
rather than 16. No idea why at the moment - 16 would make sense to me
as well, although there's bound to be *some* extra overhead for the
buckets etc. Possibly alignment issues? Hmm...

Jon
I just Reflector'd it. In addition to the key and the value the hash
code (int) and a next pointer (int) are also stored on each entry.
That would account for 16B. There is also an int[] array that is used
for indexing the entries array. That gets us to 20B. The resizing
algorithm uses the first prime number greater than twice the
hashtable's current size and uses that for the new size. That would
easily get you to 40.

Since we're discussing very large dictionaries I noticed that the
prime table is preloaded up to 7,199,369 (which is not to say that all
primes up to that value are included). Once it reaches that size the
next resize operation will start using the naive algorithm for
primality testing, but will *probably* yield 14,398,753, 28,797,523,
and 57,595,063. That gives us jumps to 288, 576, and 1152 MB
respectively. If the 1GB limit is indeed in play for arrays then we
might expect ~28 million to be the upper limit. Pure speculation.
Aug 13 '08 #8
On Aug 13, 4:25*pm, Brian Gideon <briangid...@yahoo.comwrote:
I just Reflector'd it. *In addition to the key and the value the hash
code (int) and a next pointer (int) are also stored on each entry.
That would account for 16B. *There is also an int[] array that is used
for indexing the entries array. *That gets us to 20B.
For some reason I didn't think that the int[] was the same length as
the main array - but I see that it is.
*The resizing
algorithm uses the first prime number greater than twice the
hashtable's current size and uses that for the new size. *That would
easily get you to 40.
Ah, I've just worked out a flaw in my test - I was only outputing the
result when the amount of memory changed, which would always give the
worst case. Printing out the best case as well shows around 20 bytes,
which now makes sense.
Since we're discussing very large dictionaries I noticed that the
prime table is preloaded up to 7,199,369 (which is not to say that all
primes up to that value are included). *Once it reaches that size the
next resize operation will start using the naive algorithm for
primality testing, but will *probably* yield 14,398,753, 28,797,523,
and 57,595,063. That gives us jumps to 288, 576, and 1152 MB
respectively. *If the 1GB limit is indeed in play for arrays then we
might expect ~28 million to be the upper limit. *Pure speculation.
Don't forget that the 1GB limit applies to individual objects AFAIK -
so only the 16 bytes per entry of the "main" array. The int[] is
separate. 57,595,063*16 = 921 521 008, which should be okay. However,
you've also got to have enough room for the old version as well, so
your whole process needs 1.5x as much memory, unless you preallocate
that capacity.

Unfortunately I don't know the exact details of all the limits, so I
won't analyse this any further, for fear of giving the wrong
information.

Jon
Aug 13 '08 #9
On Aug 13, 11:22*am, "Jon Skeet [C# MVP]" <sk...@pobox.comwrote:
Don't forget that the 1GB limit applies to individual objects AFAIK -
so only the 16 bytes per entry of the "main" array. The int[] is
separate. 57,595,063*16 = 921 521 008, which should be okay. However,
you've also got to have enough room for the old version as well, so
your whole process needs 1.5x as much memory, unless you preallocate
that capacity.
Ah yes. Good points. Also in the sake of full disclosure, that
57595063 value was based on a quick statistical test for primality so
it may not even be prime for all I know. I'm sure there is a prime
somewhere in that ballpark so it's probably not going to skew the
numbers too much.
>
Unfortunately I don't know the exact details of all the limits, so I
won't analyse this any further, for fear of giving the wrong
information.
Understood.

Aug 13 '08 #10
On Aug 13, 1:37*am, "Cor Ligthert [MVP]" <notmyfirstn...@planet.nl>
wrote:
A little bit difficult, because then all pairs should be referencing to null
and that is not possible.

Cor
Well, as long as TValue is a reference type then the value could be
null. I haven't actually tested that because I've never done it, but
it should be possible according to the documentation.
Aug 13 '08 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Benjamin Scott | last post by:
Hello. I attempted to build a compound dictionary: len(Lst)=1000 len(nuerLst)=250 len(nuestLst)=500 Dict={}
8
by: Rodd Snook | last post by:
I have an application which makes extensive use of the Scripting.Dictionary object. I'm not doing anything silly like putting them outside the page scope -- just creating quite a few of them and...
8
by: Samuel | last post by:
I have a user complaining about a random error (sporadic, cannot be reliably reproduced): ================================= Microsoft VBScript runtime error '800a01fb' An exception occurred:...
5
by: Fox | last post by:
Hi, I am working on a project which used dictionaries. I am having to remake part of this and have no experience with the scripting dictionary. I need to see how to create multiple...
2
by: John | last post by:
I am trying to design a dictionary in such a way that I can keep the interface and implementation separate. Here is my initial design. Anyone has any comments on it or suggestions on how I could...
2
by: Kums | last post by:
What is the maximum permissible size of a database? Is there any limitation. What is the maximum # of tablespace's allowed in a database? Thanks for your response.
5
by: Andrew Robinson | last post by:
I need to serialize a dictionary so I can encode the contents. I have the following working but the size seems large. I am guessing that I am serializing the entire object not just the data. Is...
8
by: Brian L. Troutwine | last post by:
I've got a problem that I can't seem to get my head around and hoped somebody might help me out a bit: I've got a dictionary, A, that is arbitarily large and may contains ints, None and more...
11
by: John | last post by:
I am coding a radix sort in python and I think that Python's dictionary may be a choice for bucket. The only problem is that dictionary is a mapping without order. But I just found that if the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.