Solved

collections vs. arrays in vb.net?

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Normally the drop down box control found in the .Net framework tools is able to select just one data and value at a time, which is displayed on the text area.   But what if you want to have multiple values to be selected in the drop down box? As …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

19 Experts available now in Live!

Get 1:1 Help Now