473,416 Members | 1,974 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,416 software developers and data experts.

.NET 2.0 Dictionary<> overhead

Hi,

I have a huge data structure, which I previosly stored in a
Dictionary<int, MyObj>
MyObj is relatively small (2 int, 1 DateTime, 1 bool).

The dictionary I am using is quite large (25,000), and I have 500 such
dictionaries.
What I've noticed is that the total memory consumed became over 1 GB.
When I changed the implementation to List<MyObj>, or SortedList<int,
MyObjthe memory consumption deteriorated drastically (to 500 -
600MB). Ofcourse, I need the fetching O(1) functionality, so the lists
are not a very good work-around.

What I am asking, is this a normal overhead?
I can hardly understand a x2 overhead between hashtables and lists. Am
I wrong here?
Do you know of a more efficient implementation of a Dictionary object?

Dec 7 '06 #1
1 2507
"Eran" <dv********@gmail.coma écrit dans le message de news:
11**********************@j72g2000cwa.googlegroups. com...

| I have a huge data structure, which I previosly stored in a
| Dictionary<int, MyObj>
| MyObj is relatively small (2 int, 1 DateTime, 1 bool).
|
| The dictionary I am using is quite large (25,000), and I have 500 such
| dictionaries.
| What I've noticed is that the total memory consumed became over 1 GB.
| When I changed the implementation to List<MyObj>, or SortedList<int,
| MyObjthe memory consumption deteriorated drastically (to 500 -
| 600MB). Ofcourse, I need the fetching O(1) functionality, so the lists
| are not a very good work-around.
|
| What I am asking, is this a normal overhead?
| I can hardly understand a x2 overhead between hashtables and lists. Am
| I wrong here?
| Do you know of a more efficient implementation of a Dictionary object?

How are you measuring the memory ? Don't forget, memory for lists tends to
get allocated in double the previous allocation as the list grows

Then do a quick count of the memory required for 500 x 25,000 x the instance
size of your object, plus 500 x 25,000 x the instance size of an int, plus
the instance size of the 500 empty Dictionary<,objects. Then factor in the
memory fragmentation caused by adding items one at a time, allowing for the
memory manager reallocating every time the present allocation is exceeded.

No, I don't think it is particularly excessive, compared with List<>.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Dec 7 '06 #2

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

Similar topics

2
by: ESPNSTI | last post by:
Hi, I'm trying to use a generics dictionary with a key class that implements and needs IComparable<>. However when I attempt to use the dictionary, it doesn't appear to use the IComparable<> to...
8
by: Brian P | last post by:
I want to expose a property of Dictionary<string, MyAbstractClass>. I tried to do it this way: private Dictionary<string, MyChildClass> _dictionary; public Dictionary<string,...
7
by: Andrew Robinson | last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v> depending on input parameters and options to the method. 1. Is there any way to convert from a dictionary to a list...
4
by: Peter K | last post by:
Hi are there any benefits in using StringDictionary over Dictionary<string, string? It appears they achieve the same thing... (I could be wrong of course). thanks, Peter
4
by: Mark S. | last post by:
Hello, I have a series of changing string IDs that are loaded dynamically a couple times a minute. I need to associate each ID with a different static class so later on in the app's lifecycle it...
8
by: Peter Larsen [CPH] | last post by:
Hi, How do i concat two dictionaries aka the following sample: Dictionary<int, stringa; Dictionary<int, stringb; b.Add(a); What is the easiest way to concat two dictionaries ??
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.