?
Solved

collections vs. arrays in vb.net?

Posted on 2002-07-25
5
Medium Priority
?
846 Views
Last Modified: 2008-02-26
1. would u know if a collection is quicker or slower than an array?

2. which of the two are more memory efficient?

Thanks
0
Comment
Question by:Massiel_VB
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 23

Expert Comment

by:naveenkohli
ID: 7178874
Collections are more efficient than array. When you instantiate an collection it allocates a buffer of memory for storing N number of entries. Therefore when you add items to it, there is no overhead of new allocations and cleanup. Whereas in case of array, to add more entries than the capacity, new meory is created and previous obe cleaned up.
0
 
LVL 1

Expert Comment

by:wford
ID: 7179019
both collections and arrays implement the Icollection interface, but how they do it changes (some that are called arrays seem to behave more like collections).

in some cases an array will be faster and better, in others a collection..

as a guide, the array classes are better for fixed data,
collections for more dynamic data (because of the cleanup and reallocation in arrays ).
sortarrays for sorting large lists, etc..

you need to do a bit of reading in the help and pick the type that suits the application.

0
 
LVL 6

Expert Comment

by:anthony_glenwright
ID: 7181616
Have a look at the entire system.collections namespace.  There's arrays, Arraylists, hashtables and a bunch of special-purpose collections in there...

The straight "collection" object is a legacy support object for VB6 developers...
0
 
LVL 5

Accepted Solution

by:
Yog earned 75 total points
ID: 7182917
Arrays provide fast lookup and storage of key-data pairs that are contiguous in memory.

Indexing a dictionary is slower than indexing an array

If you have more data, meaning around 10,000 - 100,000 to store, go for an dictionary

else i guess you can go for an array :)

these things apply, when it comes to scripting languages, the semantics of scripting languages need that a temporary copy of array is made when you try to access an element of an array, so dont use array if your item list is big  :)

cheers.
0
 

Expert Comment

by:inquisitive123
ID: 11953434
I am having trouble creating an array of objects and accessing them.  I am creating a global array of bufferred stream objects.  I am initializing the array using setvalue in function 1.  Then I am accessing the array in function 2.  But I am getting a null reference error for the object.  Please help me out here.

Thanks
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question