Solved

collections vs. arrays in vb.net?

Posted on 2002-07-25
5
838 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
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 25 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML & .net 5 40
Please explain "Multi-Tenant Services" 5 63
How can I use SQL Stored Procedure to return FedEx Zone 17 41
Variable Event ? 3 22
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now