locked
ArrayList Vs List Vs Hashtable for frequent retrieval RRS feed

  • Question

  • Hi All,

    I have a definite set of items(around 3000) whose value needs to be added to a collection. Updation to these value will be there but not very frequent. However, there will be frequent retrieval of information required from  this collection.

    Which one of arrraylist, list,hashtable or any other collection object would be the best fit to implement this collection.

    Cheers

    TicArch

    Thursday, April 15, 2010 3:45 AM

Answers

  • hi,

    Dictionary<T> would be good considering frequent retrival of item.

    Regards,

    Vinil;

    • Marked as answer by TicArch Saturday, April 24, 2010 5:03 PM
    Thursday, April 15, 2010 4:37 AM
  • Hi TicArch,

    Dictionary will take a Key and a object it would be like Dictionaty<TKey,TValue>, generics in in place to reduce the boxing andd unboxing rather casting overhead.

    When you defile a collection , you are specifying the type of the objects that are in the collection hence you need not do explicict casting after retriving the element from the cllection, which we used to do in the earlier days when we were using just ArrayList instead of ArrayList<T>

    Hope this helps

    Thanks

    Gags

    • Marked as answer by TicArch Saturday, April 24, 2010 5:03 PM
    Friday, April 16, 2010 5:30 AM
  • Assuming frequent indexed reads then memory usage is probably less of an issue than read time.

    Whatever you do, you'll need the type defined and something to read the data and stick it in your type.  The code to then append this to a hashtable isn't going to exactly be huge.

    I would put together the hashtable as a PoC and then take a look at how much memory it's using if you're concerned. You can use a CLR profiler to examine specific memory use. 

    • Marked as answer by TicArch Saturday, April 24, 2010 5:03 PM
    Friday, April 16, 2010 10:36 AM

All replies

  • hi,

    Dictionary<T> would be good considering frequent retrival of item.

    Regards,

    Vinil;

    • Marked as answer by TicArch Saturday, April 24, 2010 5:03 PM
    Thursday, April 15, 2010 4:37 AM
  • Hi Vinil,

    What all parameters will dictionary take for storage, and where do it lack compared to others.Don't you think, use of genrics will affect the performance due to boxing and unboxing

    This will help me in judging the alternative incase any other trade off condition appears.

    Will hashtable hamper performance or memory utilisation.

    Cheers

    TicArch

    Thursday, April 15, 2010 4:40 AM
  • Generics - what boxing overhead?

     

    Thursday, April 15, 2010 10:13 AM
  • Hi TicArch,

    Dictionary will take a Key and a object it would be like Dictionaty<TKey,TValue>, generics in in place to reduce the boxing andd unboxing rather casting overhead.

    When you defile a collection , you are specifying the type of the objects that are in the collection hence you need not do explicict casting after retriving the element from the cllection, which we used to do in the earlier days when we were using just ArrayList instead of ArrayList<T>

    Hope this helps

    Thanks

    Gags

    • Marked as answer by TicArch Saturday, April 24, 2010 5:03 PM
    Friday, April 16, 2010 5:30 AM
  • Assuming frequent indexed reads then memory usage is probably less of an issue than read time.

    Whatever you do, you'll need the type defined and something to read the data and stick it in your type.  The code to then append this to a hashtable isn't going to exactly be huge.

    I would put together the hashtable as a PoC and then take a look at how much memory it's using if you're concerned. You can use a CLR profiler to examine specific memory use. 

    • Marked as answer by TicArch Saturday, April 24, 2010 5:03 PM
    Friday, April 16, 2010 10:36 AM