Solved

Hashtable is very slow

Posted on 2004-08-24
5
326 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
5 Comments
 
LVL 84

Expert Comment

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 115
MacOS and programming in React 7 41
Identify two keyboard codes and how to enter them 9 55
Bot application - advice 3 38
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

839 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