Solved

Pros and Cons of List vs Dictionary for in-memory proxies of DB Tables

Posted on 2014-01-01
2
251 Views
Last Modified: 2014-01-05
I've got an ASP.NET app that currently uses DataSets and TableAdapters, and thus makes heavey use of typed DataRows.

I'm going to convert this to Connected Data Access as described here:

http://msdn.microsoft.com/en-us/data/ff707264.aspx#_Toc261428884

(FYI, I'm not going with anything more abstract, like Entity Framework, in order to maintain migratability)

The example at that link uses Lists as in-memory proxies for the DB tables.

I recently learned that Dictionaries can be searched much faster that Lists, for unique IDs, which I can arrange for have in all the tables I'm using.  Also, Dictionaries can be Typed.

What I'm hoping for is input on the Pros and Cons of List vs Dictionary for these in-memory proxies of DB Tables.

Any help with this would be appreciated.

Thanks!
0
Comment
Question by:codequest
2 Comments
 
LVL 16

Accepted Solution

by:
Stephan earned 500 total points
ID: 39751043
These are a few things that I know about Lists and Dictionaries

Pros dictionary:
Has the smallest memory print
is faster when they have a large set of data

Cons dictionary:
Dictionaries don't have any sort capability

Pros list:
Is faster depending on the field (e.g. string value is faster in lists than dictionaries)
Lists are in a way sorted on insertion

Cons list:
It is getting really slow when the set if data is getting bigger

Big thing between lists and dictionaries is that dictionaries has it's on hash table for the keys. For example, integers are way faster than string values on a hash table.

So I think it really depends on what you want to do with the data.
Most people prefer Lists because there are more flexible because you don't need a key.
But on performance and memory it is recommended to use a Dictionary but it depends what you want to do exactly.

Here is a blog post that takes a quick look at "HashSet vs List vs Dictionary"
http://theburningmonk.com/2011/03/hashset-vs-list-vs-dictionary/
0
 
LVL 2

Author Comment

by:codequest
ID: 39756385
Thanks for input.  Good info.   I'll think on this, see if there are other responses, then close out.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now