Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 31-07-2009
Member
 
Join Date: Jan 2009
Posts: 42
C# Hashtable vs list vs dictionary

Hello everyone,

I am writing a program codes for a game in XNA/C# in which i use Hashtables in order to save my several objects. But each time I need to get an object I have to search in the Hashtable for the key, 60 times per second.While I'm drawing my things to the screen I get a performance drop once in a while. So I'm wondering, which is the best method to save and retrieve objects? A hashtable, an (array)list or a dictionary (never used a dictionary before)?

thanks in advance !!
Reply With Quote
  #2  
Old 31-07-2009
Member
 
Join Date: Oct 2005
Posts: 2,389
Re: C# Hashtable vs list vs dictionary

Better you should determine the scale.You trying to store considerable large amount of data and looking for large amounts of it at once or what?Use a database to sync it to hard disc. Otherwise, use a Dictionary object. Completely in-memory objects are always going to be faster than anything that requires communicating with an external interface (DB access).On contrary there is a built-in Collection, but the Dictionary is faster for string stuff i Guess.lately, given that your top priority is performance, you should determine whether or not you really want to use an object to save the information. If you write your own traversion routine to query values, it could. It might be a lot of hack work to build something quicker than the Dictionary class though.
Reply With Quote
  #3  
Old 31-07-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
Re: C# Hashtable vs list vs dictionary

I know that Hastable class have load factor for performance tweaking. But i think we can't compare the two simply becose they are not in similar implementation (hashtable for key-value pair, arraylist for storing variable number of objects) and usage.Anyway we can compare them to their counterparts, say like use SortedList if you want your key-value pair automatically sorted, there's no reason to use hashtable and create a separate implementation for sorting its values. It's a matter of careful design and right class selection
Reply With Quote
  #4  
Old 31-07-2009
Member
 
Join Date: Apr 2008
Posts: 1,948
Re: C# Hashtable vs list vs dictionary

My opinion is the lowest level possible is best to begin with.When we get some more folks using and thinking about this, we can discuss whether it makes more sense in the .NET world to use the Generics within the framework or not.As expected SortedDictionary is slower for insertions and faster for search than Dictionary. Memory allocation is about the same SortedList uses less memory than the others but is extremely slow for insertions.However, for me, the most interesting results here are the relative performance of Hashtable compared to Dictionary. Whereas Hashtable is slower on insertions, it's much quicker on searchs (faster even than SortedDictionary) so may be it's been written off too quickly)
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "C# Hashtable vs list vs dictionary"
Thread Thread Starter Forum Replies Last Post
HashMap vs HashTable Joyjeet Software Development 6 04-01-2011 09:07 PM
Hashtable vs Vector Vodka Software Development 5 23-02-2010 02:43 AM
Manipulating a hashtable Miles Runner Software Development 5 12-02-2010 01:20 AM
Problem sorting a Hashtable Vodka Software Development 5 04-02-2010 05:16 AM
How to use hashtable to replace content RasMus Software Development 3 27-07-2009 10:30 AM


All times are GMT +5.5. The time now is 02:41 AM.