Link to home
Start Free TrialLog in
Avatar of Massiel_VB
Massiel_VB

asked on

collections vs. arrays in vb.net?

1. would u know if a collection is quicker or slower than an array?

2. which of the two are more memory efficient?

Thanks
Avatar of naveenkohli
naveenkohli

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.
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.

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...
ASKER CERTIFIED SOLUTION
Avatar of Yog
Yog

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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