Results 1 to 4 of 4

Thread: C# Hashtable vs list vs dictionary

  1. #1
    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 !!

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    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

  4. #4
    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)

Similar Threads

  1. HashMap vs HashTable
    By Joyjeet in forum Software Development
    Replies: 6
    Last Post: 04-01-2011, 09:07 PM
  2. Hashtable vs Vector
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 23-02-2010, 02:43 AM
  3. Manipulating a hashtable
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 01:20 AM
  4. Problem sorting a Hashtable
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 04-02-2010, 05:16 AM
  5. How to use hashtable to replace content
    By RasMus in forum Software Development
    Replies: 3
    Last Post: 27-07-2009, 10:30 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,040,814.50533 seconds with 17 queries