Solved

Hashtable is very slow

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Purpose To explain how to place a textual stamp on a PDF document.  This is commonly referred to as an annotation, or possibly a watermark, but a watermark is generally different in that it is somewhat translucent.  Watermark’s may be text or graph…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now