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

"cost" of generic dictionaries ?

For me Generic Dictionaries in .NET (I'm still back with 2.0 as yet ... I do
play in my favorite key of C#, thanks) are very tasty, very useful.

But, I do find myself wondering what the "overhead" (memory, look-up times)
in using them is like. And, as often as I admonish myself that I really
should go look at what the compiler writes, as often shirk descent into
those op-code lands. Yes, I know I would be a better person if I got L.
Roeder's "Reflector" and ... :)

Obviously using a value type (including structs) as keys you are not going
boxing, as you would have done using the older flavour of non-generic
dictionary. For reference types used as keys I am less certain; I am only
aware that you might have to roll your own comparer depending on what you
were storing and ...

But, let's say that you have a program that is doing a lot multiple look-ups
in GD's. Perhaps even one of the GD involved has keys, or values, or both,
that is a GD.

Appreciate hearing if anyone has developed any heuristics about the
strategic use of GD's given certain types of application scenarios.

A friend recently gave me a talking-to about using 'foreach : telling me it
was much better to just go ahead and do a for loop in terms of performance.
This has stimulated my interest in thinking about other lately arrived .NET
features like GD's in terms of memory use and look-up times..

thanks !

Bill
Feb 19 '08 #1
1 1414
avoiding the virtcalls...
Or pehaps (more likely?) it was the JIT doing its thing; but either way,
there really isn't much in it.

I also forgot to say that "foreach" better expresses intent; consider a
linked list that provided an int indexer. I would expect "foreach" to simply
walk the nodes yielding (very quick and simple) - however, it is also
entirely likely that the indexer starts at the beginning each time (since
there is no notional state to retain) - hence the indexer (for) would
actually telescope with O(n^2) performance, where-as foreach would be linear
O(n). Of course, the standard LinkedList<Tdoesn't provide an indexer, so
it is a mute point - but ir highlights that you should be worrying about
what you want to achieve, and (until proven otherwise by repeatable
benchmarks) let the runtime and base-libraries worry about the rest.

Anything else is premature optimisation.

Marc
Feb 19 '08 #2

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

Similar topics

4
by: Teddy | last post by:
If I use just a STL container such as std::vector in my program. Is "using std::vector;" better than "using namespace std" ? Does "using namespace std" cost ?
10
by: Greg Stark | last post by:
This query is odd, it seems to be taking over a second according to my log_duration logs and according to psql's \timing numbers. However explain analyze says it's running in about a third of a...
10
by: Clint | last post by:
Hey all - I'm having a really confusing problem concerning a web service. Right now, I have an application that needs to call a web service that does nothing but return "true" (this will...
2
by: Zygo Blaxell | last post by:
I have a table with a few million rows of temperature data keyed by timestamp. I want to group these rows by timestamp intervals (e.g. every 32 seconds), compute aggregate functions on the...
13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
28
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are...
93
by: jacob navia | last post by:
In this group there is a bunch of people that call themselves 'regulars' that insist in something called "portability". Portability for them means the least common denominator. Write your code...
10
by: Wildemar Wildenburger | last post by:
Hi there :) I don't know how else to call what I'm currently implementing: An object that behaves like a list but doesn't store it's own items but rather pulls them from a larger list (if they...
30
by: Medvedev | last post by:
i see serveral source codes , and i found they almost only use "new" and "delete" keywords to make they object. Why should i do that , and as i know the object is going to be destroy by itself at...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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
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...

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.