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

Size of Dictionary Object

Hi All,

I have to make multiple dictionary objects(Dictionary<string key, int
value>) with same set of string keys, and that really eats up lot of
space. I am trying to find a solution where I can save space- In my
current implementation all dictionary objects store the same keys
repetitively and that eats up lot of space. Does .net framework comes
to help in such situation?

The best I can think of is having a separate dictionary object which
maps given set of string keys to set of unique integers, and then use
that unique integers to map to value - this way I don;t have to store
string keys multiple times. Can someone suggest me a better solution.

Thanks,
Shrish

Jun 1 '06 #1
3 11353
Shrish,

I'm not exactly sure what you're trying to accomplish, but is each
Dictionary storing integers for the values (but using the same keys)?

If so, you could use an int[] as the value. If not, maybe you can use
another type of array or collection.

Also, if you need some sort of identifier for the values you are
storing, you could use Dictionary<string, Dictionary<string, int>> which
would give you just 1 key, and then a dictionary for that key with
strings and integers.

Hope this helps.

Dan Manges
Jun 1 '06 #2
Why not just use a structure as the value, which has fields which store
the possible values.

For example, if one Dictionary is a Dictionary<string, MyObject> and
another is Dictionary<string, MyObject2>, then you could do this:

public struct MyObjects
{
public MyObject MyObject;
public MyObject2 MyObject2;
}

And then use a Dictionary<string, MyObjects>, setting the appropriate
fields, and using only one set of keys.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dan Manges" <da***********@gmail.com> wrote in message
news:0X******************@tornado.ohiordc.rr.com.. .
Shrish,

I'm not exactly sure what you're trying to accomplish, but is each
Dictionary storing integers for the values (but using the same keys)?

If so, you could use an int[] as the value. If not, maybe you can use
another type of array or collection.

Also, if you need some sort of identifier for the values you are storing,
you could use Dictionary<string, Dictionary<string, int>> which would give
you just 1 key, and then a dictionary for that key with strings and
integers.

Hope this helps.

Dan Manges

Jun 1 '06 #3
Would this kind of approach help:

//(using System.Collections)

SortedList sortedList = new SortedList();
ArrayList arrayList1 = new ArrayList();
ArrayList arrayList2 = new ArrayList();

arrayList1.Add(1);
arrayList1.Add(3);
arrayList1.Add(5);

arrayList2.Add(0);
arrayList2.Add(2);
arrayList2.Add(4);

string strKey1 = "int collection one";
string strKey2 = "int collection two";

sortedList.Add(strKey1, arrayList1);
sortedList.Add(strKey2, arrayList2);

IDictionaryEnumerator oIDictionaryEnumerator =
sortedList.GetEnumerator();

while (oIDictionaryEnumerator.MoveNext())
{
Console.WriteLine("key = {0}",
oIDictionaryEnumerator.Key);

ArrayList arrayList = oIDictionaryEnumerator.Value as
ArrayList;
IEnumerator oIEnumerator = arrayList.GetEnumerator();
while (oIEnumerator.MoveNext())
{
Console.WriteLine("value = {0}",
oIEnumerator.Current);
}
}

Jun 2 '06 #4

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

Similar topics

6
by: Johnny Klunk | last post by:
Wondering if someone can give me a hand with something that I'm sure is really easy - but damned if I know what I'm doing wrong. I'm trying to read the contents of a database into an ASP...
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...
1
by: boohoo | last post by:
I can't seem to do this: I want to take a query string and place two halves of the querystring into two separate dictionary objects. So... I loop through the collection of querystring items,...
5
by: TWiSTeD ViBE | last post by:
Hi, While pouring over some code I've discovered a previous developer heavily uses the "dictionary" object. Whilst I see some of the advantages of using this system It's something I've not used...
26
by: Alan Silver | last post by:
Hello, I have a server running Windows Server 2003, on which two of the web sites use the MegaBBS ASP forum software. Both sites suddenly developed the same error, which seems to be connected to...
4
by: CharlesEF | last post by:
Hi All, This has me stumped. I have used a VBScript dictionary object to load column names and their values so I can use them when I build the web page. When I do this, I get the correct...
1
by: john wright | last post by:
I have a dictionary oject I created and I want to bind a listbox to it. I am including the code for the dictionary object. Here is the error I am getting: "System.Exception: Complex...
4
by: Betina Andersen | last post by:
I have a dictionary object, then I create a new dictionary object and sets it equal to my original, then I pass the new dictionary object to a function that changes some of my values - but then my...
15
by: Dave Young | last post by:
I'm trying to replicate the behaviour of the Commerce.Dictionary object that was found in Commerce Server 3.0 By using a hashtable or creating a custom class that implements IDictionary, you...
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: 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
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...
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
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.