Re: Efficiency about hashtable, arraylist, string and synchronization
- From: "Marc Gravell" <marc.gravell@xxxxxxxxx>
- Date: Fri, 27 Oct 2006 15:42:33 +0100
Hashtable, but not your way ;-p
The string option is bad. Don't go near it. Firstly you would need a
delimiter, but mainly because strings are immutable (and hence your code is
actually wrong). You would need sList = sList.Replace(id,""); but now you
have multiple lock objects; OK you could avoid this with a separate lock,
but you are still making *lots* of strings.
Personally I also wouldn't go near the .Synchronized options... I'd just:
lock(hList) {
hList.Add(id);
}
etc; this way you know the duration of the lock, so you can safely do
multiple steps as an atomic unit:
lock(hList) {
if(!hList.Contains(id)) {
hList.Add(id,id); // value is dummy
}
}
Note also that (assuming ID is an integer) this will involve boxing; if you
can, I would suggest moving to 2.0 and using a Dictionary<int,int>.
Marc
.
- Prev by Date: Re: Efficiency about hashtable, arraylist, string and synchronization
- Next by Date: Re: Add ComboBoxes in runtime based on user input, how?
- Previous by thread: Re: Efficiency about hashtable, arraylist, string and synchronizat
- Next by thread: deserialize and utf8 encoding
- Index(es):
Relevant Pages
|