Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Hashtable is very slow

Posted on 2004-08-24
5
Medium Priority
?
367 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 85

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 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Screencast - Getting to Know the Pipeline

972 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