Solved

Hashtable is very slow

Posted on 2004-08-24
5
353 Views
Last Modified: 2010-04-17
Hi,
I am using Hashtable to store my data (key - Integer, value - ArrayList) .. When I call my Hashtable the response time is very long although i have only 22 key,values in my Hashtable.  Any idea why?
Thanks !
germess
0
Comment
Question by:germess
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 11883501
How are you implementing your hashtable?
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 11883531
I have noticed in many of my apps, that the .Net collection classes are slow to respond the very first time I request a value from them.  Subsequent requests are usually executed with the speed that I expect of that collection type.

Idle_Mind
0
 

Accepted Solution

by:
Pete_Bradley earned 250 total points
ID: 11900711
Hi germess,
The types of objects you have used in your hashtable should have very little impact on its speed. All the hashtable works with are object references allocated from the heap, regardless of what types of data are being stored.
Having said that, possibly one optimisation you might use is to consider using a different data type for the key to the hashtable. Using ints requires that the processor repeatedly box and unbox the data (ie convert int to Integer and back again), and thus moving its allocation from the stack to the heap back and forth. Though very little, this does take time and could cause some slowing down if the hashtable is getting hammered over and over.
Another is that you can check the type casting code you use to extract your Arraylist objects. Using the c# 'as' operator is generally faster than regular type casting, and offers the advantage of returning null if the cast is invalid, where regular type casts throw InvalidCastExceptions.
Hope this helps,
Pete
0
 
LVL 3

Expert Comment

by:IceColdas
ID: 11902081
Are you using the debug version or the release version of your application ?
Because if u use the debug version, then it takes quite a while to deal with some functions, especially if they return null.
So i suggest you to build the release version ( from the C# menu, choose Build -> Configuration Manager, and at the Active Solution Configuration  combo box,  select Release).
0

Featured Post

Ready to get started with anonymous questions?

It's easy! Check out this step-by-step guide for asking an anonymous question on Experts Exchange.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Introduction to Processes

617 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