473,800 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.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 2541
"Eran" <dv********@gma il.coma écrit dans le message de news:
11************* *********@j72g2 00...legr oups.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<,obj ects. 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
15953
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 find the key. In the example below, accessing the dictionary by using the exact key object that was used to add to the dictionary works. (see code comment 1). However, if I attempt to access the dictionary by using a key object that
8
17841
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, MyAbstractClass> { get { return _dictionary; } //error: no implicit conversion. }
7
57556
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 without itterating through the entire collection and building up a list? 2. is there a common base class, collection or interface that can contain either/both of these collection types and then how do you convert or cast from the base to either a...
4
10683
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
4869
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 knows which static class to use for processing. I've tried: static class MyStaticObject {
8
7116
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
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10274
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10033
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7576
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.