473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

2.0 Collections data

Hi,

1) Is it worth to replace all HashTable and ArrayList (framework 1.1) usage
by Dictionary and List (framework 2.0) ?

I suppose the answer would be yes as the 2.0 collections are type safe and
should perform better.
But are there as reliable ?

2) In a multithreading environment, what is the best way to prevent
concurrent accesses ?

For now, I implemented a static function that returns a clone copy of the
data collection (protected by a lock based on the SyncRoot property of the
data collection). This copy is used by all running threads that needs read
or write access to collection elements. Is it necessary as the collection
object is not modified, only its elements are (add to and remove elements
from collection is also protected by a lock on SyncRoot property).
Thanks in advance,

Droopy.
Sep 19 '06 #1
5 1231
1) Depends on whether or not you can type your collections. if so, moving to
the generci list and dictionary is a good idea. Example:

List<intDictionary<int, customer>

2) You should always have a monitor of some sort to guarantee consistent
state. This can be the Monitor class or a Mutex, both of which have plenty
of examples on the web.

In your case, if possible, you should only exclusively lock when you are
changing data, lest you lock up threads needlessly.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
"Droopy" <dr**************@hotmail.comwrote in message
news:Xn**********************************@195.129. 110.71...
Hi,

1) Is it worth to replace all HashTable and ArrayList (framework 1.1)
usage
by Dictionary and List (framework 2.0) ?

I suppose the answer would be yes as the 2.0 collections are type safe and
should perform better.
But are there as reliable ?

2) In a multithreading environment, what is the best way to prevent
concurrent accesses ?

For now, I implemented a static function that returns a clone copy of the
data collection (protected by a lock based on the SyncRoot property of the
data collection). This copy is used by all running threads that needs read
or write access to collection elements. Is it necessary as the collection
object is not modified, only its elements are (add to and remove elements
from collection is also protected by a lock on SyncRoot property).
Thanks in advance,

Droopy.

Sep 19 '06 #2
"Cowboy \(Gregory A. Beamer\)" <No************@comcast.netNoSpamMwrote
in news:#M**************@TK2MSFTNGP04.phx.gbl:
1) Depends on whether or not you can type your collections. if so,
moving to the generci list and dictionary is a good idea. Example:

List<intDictionary<int, customer>

2) You should always have a monitor of some sort to guarantee
consistent state. This can be the Monitor class or a Mutex, both of
which have plenty of examples on the web.

In your case, if possible, you should only exclusively lock when you
are changing data, lest you lock up threads needlessly.
I think I was not precise enough for the second point.
When using the clone copy, I don't change the data collection so I should
not need locking but I read the whole collection with a foreach.
I think I read somewhere that there is a potential problem if the
collection is changed while a read with a foreach is performed.

Thanks already for your help.
Sep 19 '06 #3
Hi,

"Droopy" <dr**************@hotmail.comwrote in message
news:Xn**********************************@195.129. 110.71...
Hi,

1) Is it worth to replace all HashTable and ArrayList (framework 1.1)
usage
by Dictionary and List (framework 2.0) ?
Are you having problem with them?
What is the cost of modifying the code? Remember that you will have to move
your code to 2.0 so others problems can arise at this point.
I suppose the answer would be yes as the 2.0 collections are type safe and
should perform better.
But are there as reliable ?
Yes, they are and they can indeed improve the performance, especially if you
have collections of valued types. Boxing/Unboxing can be an expensive
operation.
2) In a multithreading environment, what is the best way to prevent
concurrent accesses ?
Sync access to the collection.
Some collections already implement it, take a look at Queue

--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Sep 19 '06 #4
"Ignacio Machin \( .NET/ C# MVP \)" <ignacio.machin AT dot.state.fl.us>
wrote in news:eW*************@TK2MSFTNGP02.phx.gbl:
Hi,

"Droopy" <dr**************@hotmail.comwrote in message
news:Xn**********************************@195.129. 110.71...
>Hi,

1) Is it worth to replace all HashTable and ArrayList (framework 1.1)
usage
by Dictionary and List (framework 2.0) ?

Are you having problem with them?
What is the cost of modifying the code? Remember that you will have
to move your code to 2.0 so others problems can arise at this point.
>I suppose the answer would be yes as the 2.0 collections are type
safe and should perform better.
But are there as reliable ?

Yes, they are and they can indeed improve the performance, especially
if you have collections of valued types. Boxing/Unboxing can be an
expensive operation.
>2) In a multithreading environment, what is the best way to prevent
concurrent accesses ?

Sync access to the collection.
Some collections already implement it, take a look at Queue
It seems that the SyncRoot property that I used to Sync doesn't exist
anymore.
How do I lock on Dictionary object (readers enumerates on the Dictionary) ?
Sep 19 '06 #5
Yes, it is possible to get a "dirty read" if the collection is changed. You
CAN alter this by putting a Mutex on the collection when updating. This will
ensure the other threads cannot access the data during the update.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside of the box!
*************************************************
"Droopy" <dr**************@hotmail.comwrote in message
news:Xn**********************************@195.129. 110.72...
"Cowboy \(Gregory A. Beamer\)" <No************@comcast.netNoSpamMwrote
in news:#M**************@TK2MSFTNGP04.phx.gbl:
>1) Depends on whether or not you can type your collections. if so,
moving to the generci list and dictionary is a good idea. Example:

List<intDictionary<int, customer>

2) You should always have a monitor of some sort to guarantee
consistent state. This can be the Monitor class or a Mutex, both of
which have plenty of examples on the web.

In your case, if possible, you should only exclusively lock when you
are changing data, lest you lock up threads needlessly.

I think I was not precise enough for the second point.
When using the clone copy, I don't change the data collection so I should
not need locking but I read the whole collection with a foreach.
I think I read somewhere that there is a potential problem if the
collection is changed while a read with a foreach is performed.

Thanks already for your help.

Sep 19 '06 #6

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

Similar topics

3
by: Sasha | last post by:
Hi everyone, Here is my problem: I have the following classes: - DataNode - this class is designed to hold some data and will be contained in a tree like data structure DataTree. When...
6
by: Chua Wen Ching | last post by:
Hi there, 1) I am looking for the best collections techniques to be used in my program. Is hashtable or arraylist or any .net collection, which is the fastest when adding, getting out data???...
3
by: juli jul | last post by:
Hello, I grid and each line of it is taken from a collection,each line represents data and for each of those lines ,I have a button that when is being pressed sub data of each line wich is also...
3
by: Rob Thomas | last post by:
Hi, I've been tasked to come up with a new architecture for a large application at one of my customer's sites. In the past, I have developed multi-tier applications whereby the business...
3
by: Paul | last post by:
Hello, I'm upgrading a small single user app to VB.NET and have a few questions about loading classes & collections classes with the data from a one to many dataset structure. I'm serializing...
6
by: Arthur Dent | last post by:
How do you sort a generic collection derived from System.Collections.ObjectModel.Collection? Thanks in advance, - Arthur Dent
1
by: dnvhari | last post by:
Hi all, we have an xml file. Based on this file we have to generate menu. This xml file changes every day. We are loading the xml file into the application memory and transforming the data of...
5
by: WebSnozz | last post by:
Some collections are such that efficient search algorithms work on them such as binary search if the collection is a type which is sorted. I'm wondering how LINQ searches these collections and if...
28
by: walterbyrd | last post by:
Python seems to have a log of ways to do collections of arbitrary objects: lists, tuples, dictionaries. But what if I want a collection of non-arbitrary objects? A list of records, or something...
0
by: bearophileHUGS | last post by:
Several languages like Java, C# etc have a List type in the std lib. Python has a built-in list(), it's implemented as array dynamic on the right. Not too much time ago Hettinger has added a...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.