473,657 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Hashtable question.

Hi,

I'm working on a Client/Server application. Server application needs to
keep
track of all the clients.

I'm planning to use a Hashtable for this purpose. There would be thousands
of
clients connect to the server application. In this case, according to my
plan,
I need to store thousands of clients along with corresponding data
in the hashtable.

Do you think storing thousands of objects( [key,value] pairs ) in the
hashtable
could lead to any problems. If so, is there any other better way of
maintaing
thousands of [key,value] pairs. Kindly let me know.

Cheers,

Naveen.
Nov 17 '05 #1
7 1758
I can't see a real problem. A HashTable is certainly the simplest way to do
what you propose. I guess it would help to ensure that what you put in has
good hash code support (GetHashCode).

Regards,

Tim Haughton

"Naveen Mukkelli" <Na************ @discussions.mi crosoft.com> wrote in
message news:EA******** *************** ***********@mic rosoft.com...
Hi,

I'm working on a Client/Server application. Server application needs to
keep
track of all the clients.

I'm planning to use a Hashtable for this purpose. There would be thousands of
clients connect to the server application. In this case, according to my
plan,
I need to store thousands of clients along with corresponding data
in the hashtable.

Do you think storing thousands of objects( [key,value] pairs ) in the
hashtable
could lead to any problems. If so, is there any other better way of
maintaing
thousands of [key,value] pairs. Kindly let me know.

Cheers,

Naveen.

Nov 17 '05 #2
Naveen Mukkelli wrote:
Do you think storing thousands of objects( [key,value] pairs ) in the
hashtable
could lead to any problems. If so, is there any other better way of
maintaing
thousands of [key,value] pairs. Kindly let me know.


If the most important operation is lookup you cannot beat hashing. but
declare it as IDictionary and instantiate it as Hashtable. That way you
don't pin yourself to using System.Collecti ons.Hashtable for
implementation.

You should be able to have millions of entries in hashtables and still
have *very* efficient (O(1)) lookup and removal (provided you have
enough RAM ;).

In all situations of disconnected operation with server-storage, you
will need to consider what to do with "dead" items. Some cleanup will
need to be done to prevent the dictionary from filling up with old
connections that will never be used later. The most common technique is
"timeout", where each stored item will be expunged when a certain
timeout expires.

--
Helge Jensen
mailto:he****** ****@slog.dk
sip:he********* *@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #3
You should be able to have millions of entries in hashtables and still
have *very* efficient (O(1)) lookup and removal (provided you have enough
RAM ;).

Hashtables performs better when they are about 75% full.
Regards,
Lars-Inge Tønnessen

Nov 17 '05 #4

"Lars-Inge Tønnessen [VJ# MVP]" <http://emailme.larsing e.com> wrote in
message news:et******** ******@tk2msftn gp13.phx.gbl...
Hashtables performs better when they are about 75% full.


Please tell me why this is true. I would love to read your explanation... =)

I would say that hastables perform best when its fill-ratio is 1/4.

- Michael S

Nov 17 '05 #5
All,

Keeping in mind that you cannot make generalizations of this kind
regarding every hashtable we should all assume that we are specifically
talking about the System.Collecti ons.Hashtable. The 75% figure cited
may have been based on the default load factor Microsoft chose for
their implementation which is 0.72. That means the Hashtable will
never be more than 72% full. If an item is inserted that would bring
the table over that threshold then an expansion occurs. That value was
chosen to optimally balance space and runtime efficiency based on
Microsoft's implementation. Since quadratic probing is used for the
basis of their implementation the size of the table is a prime number.

If by performance you mean the balance between space and runtime
efficiency then a fill ratio of no more than ~75% is optimal for the
..NET Hashtable. In general, though, lower fill ratios result in faster
runtimes, but more memory.

<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/dv_vstechart/html/datastructures_ guide2.asp>

Brian

Michael S wrote:
"Lars-Inge Tønnessen [VJ# MVP]" <http://emailme.larsing e.com> wrote in
message news:et******** ******@tk2msftn gp13.phx.gbl...
Hashtables performs better when they are about 75% full.


Please tell me why this is true. I would love to read your explanation...= )

I would say that hastables perform best when its fill-ratio is 1/4.

- Michael S


Nov 17 '05 #6
Thanks for the indepth explanation Brian.

Happy Coding
- Michael S

"Brian Gideon" <br*********@ya hoo.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
All,

Keeping in mind that you cannot make generalizations of this kind
regarding every hashtable we should all assume that we are specifically
talking about the System.Collecti ons.Hashtable. The 75% figure cited
may have been based on the default load factor Microsoft chose for
their implementation which is 0.72. That means the Hashtable will
never be more than 72% full. If an item is inserted that would bring
the table over that threshold then an expansion occurs. That value was
chosen to optimally balance space and runtime efficiency based on
Microsoft's implementation. Since quadratic probing is used for the
basis of their implementation the size of the table is a prime number.

If by performance you mean the balance between space and runtime
efficiency then a fill ratio of no more than ~75% is optimal for the
..NET Hashtable. In general, though, lower fill ratios result in faster
runtimes, but more memory.

<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/dv_vstechart/html/datastructures_ guide2.asp>

Brian

Michael S wrote:
"Lars-Inge Tønnessen [VJ# MVP]" <http://emailme.larsing e.com> wrote in
message news:et******** ******@tk2msftn gp13.phx.gbl...
Hashtables performs better when they are about 75% full.


Please tell me why this is true. I would love to read your explanation...
=)

I would say that hastables perform best when its fill-ratio is 1/4.

- Michael S

Nov 17 '05 #7

A statement like "X is most efficient when Y" generally means that one
should strive to fullfill Y in order to improve efficiency. This is
definatly not true here, adding more elements to the hash-table without
re-hashing does *not* improve lookup or insert efficiency.

There really is a lot of freedom in the definition of even the
*statement* here. When is a hash-table most efficient? are we talking
worst-case or average lookup-time, insertions? memory consumption?
latency-time on rehashes? ...

Real hash-tables lookup and insert-performance doesn't depend on how
"full" they are. They use rehashing when "too many" key-collisions
occur, and can (given that the hash-function is, what's called
"universal" -- which is a specific way of saying it's good) be proven to
provide amortized O(1) insert, lookup and removal operations using O(N)
memory.

System.Collecti ons.Hashtable is a pretty good implementation -- with an
acceptable tradeoff between space and performance, and basically you
should only think about "tuning" anything about it if you have run a
profiler and shown that the performance problem lies there.

--
Helge Jensen
mailto:he****** ****@slog.dk
sip:he********* *@slog.dk
-=> Sebastian cover-music: http://ungdomshus.nu <=-
Nov 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8709
by: francois | last post by:
Hi, I have a webservice that I am using and I would like it to return an XML serialized version of an object. the class of the object is defined serializable as the following: public class Event {
5
2816
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would like it to return an XML serialized version of an object.
5
15573
by: Cyrus | last post by:
I have a question regarding synchronization across multiple threads for a Hashtable. Currently I have a Threadpool that is creating worker threads based on requests to read/write to a hashtable. One function of the Hashtable is to iterate through its keys, which apparently is inherently not thread-safe. Other functions of the Hashtable include adding/modifying/deleting. To solve the synchronization issues I am doing two things: 1. Lock...
33
3307
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are used before adding, removing or iterating the Hashtable. The program runs in a high workload environment. After running a few days, now it suddenly catchs this Exception when inserting a pair of key and object, stacktrace =...
5
1499
by: ad | last post by:
I have a hashtable name myHash. sKey is a string, I use myHash to retrieve the value of that key. But is sKey is not in the myHash.Keys, it raise an Exception. I want to dertiminate if sKey in myHash.Keys. How can I do that?
2
5458
by: Ali | last post by:
I am binding a hashTable to a dropDownList to pick a State (key: like New York) and sends the state designation (value: NY) to a filtering procedure. I have entered the states in the hashTable in alphabetical order, but the dropDownList renders them in a non-order list. code snippet: Dim state as New hashTable state.Add("Alabama", "AL") state.Add("Alaska", "AK")
8
1683
by: Robin Tucker | last post by:
When I create a hashtable hashing on Object-->Item, can I mix "string" and "integer" as the key types? I have a single thumbnail cache for a database with (hashed on key) and a file view (hashed on string). So, for example, when I want to know if the file "xyz.abc" is in the cache, I can write myTable.ContainsKey ( "xyz.abc" ) or if a given DB key is in the hash I can write myTable.ContainsKey ( 123 ). Or do the keys all have to be of...
4
3780
by: Macca | last post by:
Hi, I am using a hashtable as a cache. I am only allowed for the cache to take up a certain amount of memory. I think I can state how large I want the hashtable to be on creation. What I need is someway to monitor the size of the hashtable so that as it nears the maximum size I have set, I can delete some item or empty the table altogether.
2
3141
by: PAzevedo | last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from multiple threads, now the Hashtable object is thread safe for reading, but not for writing, so I lock the object every time I need to write to it, but now it occurred to me that maybe I could just lock one of the Hashtables inside without locking the entire object, but then I thought maybe some thread could instruct the outside Hashtable to remove an inside Hashtable...
2
3874
by: archana | last post by:
Hi all, I am having one confusion regarding hashtable. I am having function in which i am passing hashtable as reference. In function i am creating one hashtable which is local to that function. Then i am setting this hash table to hashtable which i am passing as ref. So my question is how scope is mention when i am assigning local
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.