Faster, ArrayList or Arrays?

melegant

Regular
Joined
Feb 2, 2003
Messages
52
Location
NY
Well, with all this talk of arrays and dynamic arrays and such, i did some looking.

now take for instance

Visual Basic:
Dim arrTXT(4) As Textbox
arrTXT(0) = txtFirstName
arrTXT(1) = txtLastName
'etc

Class.Method(arrTXT)

or

Visual Basic:
Dim arrTXT as Arraylist
arrTXT.Add(txtFirstName)
arrTXT.Add(txtLastName)
'etc

Class.Method(arrTXT)

Which would be faster, (Arrayslists seem to be much more flexible)and in the Class Method does it make a difference speed wize using ByRef in the method signature vs ByVal (I thought arrays always were passed by reference)

Thanks (:
 
It all depends on what you're going to be using it for. ArrayLists can
be used like collections, where you can add, remove and insert
objects of any kind. Arrays are generally best if the data is going to
be accessed by index, because the index of an item in an array won't
change; ArrayList items can be removed, which will renumber all of
the items in the ArrayList.

You don't use one instead of the other, as they both have their places.
ArrayLists are good for storing a collection of objects, arrays are good
when you need to have an index->data relationship (just one example).
 
Thanks for the info..

I use arrays a lot to pass to methods, however i am faced with a situation where if i had a flexible array, or dynamic ..then i could build a very poweful small routine to fill any amount of text boxs i send it. I can make an array work, but i would have to use a select case statement and dim the array within each to corrospond to the amount of textboxes i am sending it.

I could use a single declration of an arraylist however and avoid that...however I would have to code adding and removing items.

there are ups and downs to both i guess. What I am wondering most though is which has better performance...(and my question regarding ByRef)

Thanks.


;)
 
Back
Top