473,320 Members | 1,950 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,320 software developers and data experts.

Which Collection class to use

I'm writing an NT service to provide security information enterprise wide. I would like to have all of this information cached
memory if a previous request loaded it into memory. Then using a common interface I would be able to invalidate and unload old
information as it is updated (Removing the item from the collection?)

My big question is what collection class will give me the greatest flexibility and greatest performance?

I hope this is clear... I really don't know how to describe what I'm trying to say.
Nov 21 '05 #1
13 1401
IMHO, a hashtable would be a good choice. I'm not sure what kind of
information you are planning to store but I assume it would be some object
most likely with some unique identifier. You can add the information to the
hashtable as:

dim oHash as New Hashtable
o.Add(ID, mySecurityObject)

Then, when you need to access it again (either because you want to update
the information or remove the stale information) you can do something like:

if o.Contains(ID) then
'either this...
o.Remove(ID)
'or this..
o.Item(ID) = myUpdatedSecurityObject
end if

The Contains method lets you search for an existing object in the hashtable
structure extremely fast. The only requirement is that all the keys (IDs in
this case) must be unique.

I hope that gives you a good enough idea to proceed..
Imran.
"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message
news:eN*************@TK2MSFTNGP10.phx.gbl...
I'm writing an NT service to provide security information enterprise wide. I would like to have all of this information cached memory if a previous request loaded it into memory. Then using a common interface I would be able to invalidate and unload old information as it is updated (Removing the item from the collection?)

My big question is what collection class will give me the greatest flexibility and greatest performance?
I hope this is clear... I really don't know how to describe what I'm trying to say.

Nov 21 '05 #2
Yeah, that helps. What kind of memory requirements are we talking about with this, though?

I will basically be keeping an object hierarchy in memory

"Imran Koradia" <no****@microsoft.com> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...
IMHO, a hashtable would be a good choice. I'm not sure what kind of
information you are planning to store but I assume it would be some object
most likely with some unique identifier. You can add the information to the
hashtable as:

dim oHash as New Hashtable
o.Add(ID, mySecurityObject)

Then, when you need to access it again (either because you want to update
the information or remove the stale information) you can do something like:

if o.Contains(ID) then
'either this...
o.Remove(ID)
'or this..
o.Item(ID) = myUpdatedSecurityObject
end if

The Contains method lets you search for an existing object in the hashtable
structure extremely fast. The only requirement is that all the keys (IDs in
this case) must be unique.

I hope that gives you a good enough idea to proceed..
Imran.
"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message
news:eN*************@TK2MSFTNGP10.phx.gbl...
I'm writing an NT service to provide security information enterprise wide.

I would like to have all of this information cached
memory if a previous request loaded it into memory. Then using a common

interface I would be able to invalidate and unload old
information as it is updated (Removing the item from the collection?)

My big question is what collection class will give me the greatest

flexibility and greatest performance?

I hope this is clear... I really don't know how to describe what I'm

trying to say.


Nov 21 '05 #3
Also, would I just inherit from this class or create a new hashtable and just shove my objects in there?

"Imran Koradia" <no****@microsoft.com> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...
IMHO, a hashtable would be a good choice. I'm not sure what kind of
information you are planning to store but I assume it would be some object
most likely with some unique identifier. You can add the information to the
hashtable as:

dim oHash as New Hashtable
o.Add(ID, mySecurityObject)

Then, when you need to access it again (either because you want to update
the information or remove the stale information) you can do something like:

if o.Contains(ID) then
'either this...
o.Remove(ID)
'or this..
o.Item(ID) = myUpdatedSecurityObject
end if

The Contains method lets you search for an existing object in the hashtable
structure extremely fast. The only requirement is that all the keys (IDs in
this case) must be unique.

I hope that gives you a good enough idea to proceed..
Imran.
"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message
news:eN*************@TK2MSFTNGP10.phx.gbl...
I'm writing an NT service to provide security information enterprise wide.

I would like to have all of this information cached
memory if a previous request loaded it into memory. Then using a common

interface I would be able to invalidate and unload old
information as it is updated (Removing the item from the collection?)

My big question is what collection class will give me the greatest

flexibility and greatest performance?

I hope this is clear... I really don't know how to describe what I'm

trying to say.


Nov 21 '05 #4
I believe memory shouldn't be an issue; When you add an object to the
hashtable, what you are really adding is a reference to the object which is
a 4-byte integer. Whatever collection you use to store your objects, thats
how items are going to be added to the collection - reference to your
objects (atleast for reference types; for value types I believe boxing is
involved since hashtable, arraylist, etc take in an Object type for the add
methods - although I'm not absolutely sure about that). The only extra
memory you need for hashtables is the memory required for storing the keys.
Thus, I think you should still be fine in terms of memory consumption. The
advantage that a hashtable data structure provides is the quick retrieval of
the items stored. The downside is that a hashtable does not store the items
in the sequence you added them which means you can't be sure of the order of
the items. Also, it does not have any sorting mechanism.

hope that helps..
Imran.

"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message
news:OE**************@TK2MSFTNGP09.phx.gbl...
Yeah, that helps. What kind of memory requirements are we talking about with this, though?
I will basically be keeping an object hierarchy in memory

"Imran Koradia" <no****@microsoft.com> wrote in message

news:%2****************@TK2MSFTNGP15.phx.gbl...
IMHO, a hashtable would be a good choice. I'm not sure what kind of
information you are planning to store but I assume it would be some object most likely with some unique identifier. You can add the information to the hashtable as:

dim oHash as New Hashtable
o.Add(ID, mySecurityObject)

Then, when you need to access it again (either because you want to update the information or remove the stale information) you can do something like:
if o.Contains(ID) then
'either this...
o.Remove(ID)
'or this..
o.Item(ID) = myUpdatedSecurityObject
end if

The Contains method lets you search for an existing object in the hashtable structure extremely fast. The only requirement is that all the keys (IDs in this case) must be unique.

I hope that gives you a good enough idea to proceed..
Imran.
"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message news:eN*************@TK2MSFTNGP10.phx.gbl...
I'm writing an NT service to provide security information enterprise
wide. I would like to have all of this information cached
memory if a previous request loaded it into memory. Then using a
common interface I would be able to invalidate and unload old
information as it is updated (Removing the item from the collection?)

My big question is what collection class will give me the greatest

flexibility and greatest performance?

I hope this is clear... I really don't know how to describe what I'm

trying to say.



Nov 21 '05 #5
"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message
news:eH**************@TK2MSFTNGP12.phx.gbl...
Also, would I just inherit from this class or create a new hashtable and
just shove my objects in there?


You don't need to inherit from this class. As I mentioned in my first post,
just create an instance of the hashtable and start adding your objects to
the collection.
This MSDN article has sample code:
http://msdn.microsoft.com/library/de...ClassTopic.asp
Imran.
Nov 21 '05 #6
You might wanna implement DictionaryBase if you want typed structure instead
of Object Based.

HTH
rawCoder

"Imran Koradia" <no****@microsoft.com> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...
"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message
news:eH**************@TK2MSFTNGP12.phx.gbl...
Also, would I just inherit from this class or create a new hashtable and
just shove my objects in there?
You don't need to inherit from this class. As I mentioned in my first

post, just create an instance of the hashtable and start adding your objects to
the collection.
This MSDN article has sample code:
http://msdn.microsoft.com/library/de...ClassTopic.asp

Imran.

Nov 21 '05 #7
Scott,

The class with the most posibilities is in my opinion the datatabel, it is
not necessary to use that with a database you know. Talking about
performance with this is in my opinion talking about parts of nanoseconds.

Just my thought on the general part of your message. (You even can set that
in a dataset and than save it for tempory or saving use on disk)

Cor

"Scott Meddows" <sc******************@tsged-removeme.com>
I'm writing an NT service to provide security information enterprise wide. I would like to have all of this information cached memory if a previous request loaded it into memory. Then using a common interface I would be able to invalidate and unload old information as it is updated (Removing the item from the collection?)

My big question is what collection class will give me the greatest flexibility and greatest performance?
I hope this is clear... I really don't know how to describe what I'm trying to say.

Nov 21 '05 #8
Will it be as fast as the hashtable?

"rawCoder" <ra******@hotmail.com> wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl...
You might wanna implement DictionaryBase if you want typed structure instead
of Object Based.

HTH
rawCoder

"Imran Koradia" <no****@microsoft.com> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...
"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message
news:eH**************@TK2MSFTNGP12.phx.gbl...
> Also, would I just inherit from this class or create a new hashtable and
> just shove my objects in there?


You don't need to inherit from this class. As I mentioned in my first

post,
just create an instance of the hashtable and start adding your objects to
the collection.
This MSDN article has sample code:

http://msdn.microsoft.com/library/de...ClassTopic.asp


Imran.


Nov 21 '05 #9
Scott,

Almost every collection derives from IList or Icontainer so there is not so
much diverence, even when you make your own collection and you do it right,
you implement those.

What performance are you looking for? Adding to a simple arraylist
10.000.000 objects takes one second on an avarage modern computer?

Cor
Nov 21 '05 #10
I agree with Cor - indeed, performance in terms of what? Adding to the
collection, looping the collection, retrieving items from the collection,
etc etc. You need to define your metrics for performance. If you are talking
about adding your objects to the collections, I believe most of the
collections perform more or less the same. For retrieving items from a
collection, as a I mentioned in my earlier post Hashtable (or any other
class inherited from the DictionaryBase) perform the best simply because of
the underlying data structure used to store objects by this collection. As
rawCoder mentioned, if you want a strongly typed collection, you can inherit
from the DictionaryBase class and it should perform equally well.

hope that helps...
Imran.

"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message
news:uh*************@TK2MSFTNGP15.phx.gbl...
Will it be as fast as the hashtable?

"rawCoder" <ra******@hotmail.com> wrote in message

news:%2****************@TK2MSFTNGP10.phx.gbl...
You might wanna implement DictionaryBase if you want typed structure instead
of Object Based.

HTH
rawCoder

"Imran Koradia" <no****@microsoft.com> wrote in message
news:%2*****************@tk2msftngp13.phx.gbl...
"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message news:eH**************@TK2MSFTNGP12.phx.gbl...
> Also, would I just inherit from this class or create a new hashtable and > just shove my objects in there?

You don't need to inherit from this class. As I mentioned in my first

post,
just create an instance of the hashtable and start adding your objects to the collection.
This MSDN article has sample code:

http://msdn.microsoft.com/library/de...ClassTopic.asp


Imran.



Nov 21 '05 #11
Thanks a lot for all your help, guys.

I think I'm going to try the hash table and the dictionary base and do some performance testing on each of those metrics.

Thanks

"Imran Koradia" <no****@microsoft.com> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...
I agree with Cor - indeed, performance in terms of what? Adding to the
collection, looping the collection, retrieving items from the collection,
etc etc. You need to define your metrics for performance. If you are talking
about adding your objects to the collections, I believe most of the
collections perform more or less the same. For retrieving items from a
collection, as a I mentioned in my earlier post Hashtable (or any other
class inherited from the DictionaryBase) perform the best simply because of
the underlying data structure used to store objects by this collection. As
rawCoder mentioned, if you want a strongly typed collection, you can inherit
from the DictionaryBase class and it should perform equally well.

hope that helps...
Imran.

"Scott Meddows" <sc******************@tsged-removeme.com> wrote in message
news:uh*************@TK2MSFTNGP15.phx.gbl...
Will it be as fast as the hashtable?

"rawCoder" <ra******@hotmail.com> wrote in message

news:%2****************@TK2MSFTNGP10.phx.gbl...
> You might wanna implement DictionaryBase if you want typed structure instead > of Object Based.
>
> HTH
> rawCoder
>
> "Imran Koradia" <no****@microsoft.com> wrote in message
> news:%2*****************@tk2msftngp13.phx.gbl...
>> "Scott Meddows" <sc******************@tsged-removeme.com> wrote in message >> news:eH**************@TK2MSFTNGP12.phx.gbl...
>> > Also, would I just inherit from this class or create a new hashtable and >> > just shove my objects in there?
>>
>> You don't need to inherit from this class. As I mentioned in my first
> post,
>> just create an instance of the hashtable and start adding your objects to >> the collection.
>> This MSDN article has sample code:
>>
> http://msdn.microsoft.com/library/de...ClassTopic.asp >>
>>
>> Imran.
>>
>>
>
>



Nov 21 '05 #12
Hi Cor,

Sure DataTable is by far the most usable data container facilitating easiest
data retrieval.

But compared to just a little more than an arrayList ( Dictionary Classes ),
can there be any performance loss visible to naked eye of the user ( and I
am not talking about the nanoseconds here )

There should be some place where all these benchmarks are placed for
different data structures not jsut theoritical assumptions of slow insertion
fast retrieval.

Talking about DataStructures, some of them which are not available in .NET -
are they available via third party lib or something ( Tree being missed the
most ). I see some five to six parts article on MSDN about DataStructures
using the prime and the elite language of .NET .. Ms. C# ... Why the code is
not available in VB.NET ???

Thank You
rawCoder
"Cor Ligthert" <no**********@planet.nl> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Scott,

The class with the most posibilities is in my opinion the datatabel, it is
not necessary to use that with a database you know. Talking about
performance with this is in my opinion talking about parts of nanoseconds.

Just my thought on the general part of your message. (You even can set that in a dataset and than save it for tempory or saving use on disk)

Cor

Nov 21 '05 #13
rawCoder,

Because of your question, I did a little test, creating a datatable with
columns item, name, address, city was about 3 times slower than creating the
same thing with objects in an hashtable. (I created 1000 times a table from
1000 rows in both, at me the hastable was about 3 seconds while the
datatabel about 9). When I did a test with 10 times a table from 100000
records both times doubles.

The question was however greathest flexibility and performance.

Suppose I want to get a persons with a specific name and city. With the
datatable I have a lot of very fast inbuild methods as select,
datarrowcollection.find or dataview.

The fastest method with a hashtable is probably loop through it and you
should create that loop and when you than want a collection of doubles you
even has to do more.

When you want to make another object with methods in that, feel free,
however in my opinion you would always lost in flexibility against the
datatable, and I will come everytime with a problem that is to do with the
datatable just by adding a method or using an extra ADONET class.

Cor
Nov 21 '05 #14

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

Similar topics

1
by: sayoyo | last post by:
Hi Guys, I have to implement a design in Java which is a collection class gathers several units of the same class. I was thinking about two ways to implement it. the first is to create two...
2
by: cksj | last post by:
I'm working on a VB.Net app that has State class (CA, AZ, WA...) and collection class of State. Which collection class interface can I use if want to be able to bind the collection a combo box and...
0
by: Sundown | last post by:
I am trying to create a custom button control for the web that, when clicked, disables and changes the text of itself and a bunch of other controls (in the collection). My goal is to end up with a...
4
by: Saso Zagoranski | last post by:
Hi! I need an array-type of collection when the entries would look like: object myObject, int myInt, string myString Which collection should I use? I know I could declare a multidimensional...
5
by: Oberon | last post by:
I want to create a collection of records which will be permanently available at the application level in an ASP.NET application. How should I go about that? Lets say that the record structure...
4
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
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
13
by: Dog Ears | last post by:
I've got a windows form that monitors the status of employees it polls a database every 2 seconds to fetch updates then update a underlying dataset bound to a grid using Invoke to marshal to the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.