• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

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

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
codequest
Asked:
codequest
1 Solution
 
StephanLead Software EngineerCommented:
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
 
codequestAuthor Commented:
Thanks for input.  Good info.   I'll think on this, see if there are other responses, then close out.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now