Search:
Namespaces
Discussions
.NET v1.1
Feedback
Which Collection class to use
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.languages.vb
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...
Scott Meddows
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.
Reply to this message...
Cor Ligthert
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" <
Click here to reveal e-mail address
>
> 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
[Original message clipped]
Reply to this message...
Imran Koradia (VIP)
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" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
> 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
[Original message clipped]
Reply to this message...
Scott Meddows
Also, would I just inherit from this class or create a new hashtable and just shove my objects in there?
"Imran Koradia" <
Click here to reveal e-mail address
> wrote in message news:%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Imran Koradia (VIP)
"Scott Meddows" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
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/default.asp?url=/library/en-us/cpref/html/frlrfSystemCollectionsHashtableClassTopic.asp
Imran.
Reply to this message...
rawCoder
You might wanna implement
DictionaryBase
if you want typed structure instead
of Object Based.
HTH
rawCoder
"Imran Koradia" <
Click here to reveal e-mail address
> wrote in message
news:%23F325%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Scott Meddows
Will it be as fast as the hashtable?
"rawCoder" <
Click here to reveal e-mail address
> wrote in message news:%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Imran Koradia (VIP)
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" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Scott Meddows
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" <
Click here to reveal e-mail address
> wrote in message news:%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Cor Ligthert
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
Reply to this message...
Scott Meddows
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" <
Click here to reveal e-mail address
> wrote in message news:%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Imran Koradia (VIP)
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" <
Click here to reveal e-mail address
> wrote in message
news:
Click here to reveal e-mail address
...
> Yeah, that helps. What kind of memory requirements are we talking about
with this, though?
[Original message clipped]
Reply to this message...
System.Collections.DictionaryBase
System.Collections.IList
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com