473,695 Members | 1,976 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 2536
"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
15940
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
17797
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
57551
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
10678
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
4867
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
7109
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
8625
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
8565
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
9113
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8822
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...
0
7658
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5838
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
4339
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2997
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
3
1971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.