Solved

Hashtable is very slow

Posted on 2004-08-24
5
336 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 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

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

Suggested Solutions

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…

749 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