Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

collections vs. arrays in vb.net?

Posted on 2002-07-25
5
Medium Priority
?
849 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 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 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