Solved

collections vs. arrays in vb.net?

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

Containers and Docker for Everyone

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
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)…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

707 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