15

What are the pros and contras of using a Vector.<> instead of array?

1
  • As a side note, this should be tagged flex4 flashplayer10. Commented Jul 16, 2009 at 11:30

5 Answers 5

19

From the adobe documentation page:

As a result of its restrictions, a Vector has two primary benefits over an Array instance whose elements are all instances of a single class:

  • Performance: array element access and iteration are much faster when using a Vector instance than when using an Array.
  • Type safety: in strict mode the compiler can identify data type errors such as assigning a value of the incorrect data type to a Vector or expecting the wrong data type when reading a value from a Vector. Note, however, that when using the push() method or unshift() method to add values to a Vector, the arguments' data types are not checked at compile time but are checked at run time.
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Arno! These are only the pros, are there also some contras? Concerning the better performance of Vector: some people report the contrary: see impossiblearts.com/blog/2008/06/18/fp10-vector-vs-array/… and bugs.adobe.com/jira/browse/FP-1802
It certainly looks like performance might not be the best selling point for vectors right now. Then again, one should be already used to the fact that both the Flex framework sdks and the flash player are far from being bug free.
The big contras are in my opinion that it is very new so a little buggy and that not everyone has FP10. In this test of Mike Chambers: mikechambers.com/blog/2008/08/19/… in his test is not a hugh difference between the 2 numbers. If your application is not heavily hanging on big lists I would go with Array.
2

Pro: Vector is faster than Array - e.g. see this: Faster JPEG Encoding with Flash Player 10

Contra: Vector requires FP10, and according to http://riastats.com/ some 20% of users are still using FP9

1 Comment

At the time of this comment, the non-detected version + flash 9 clocks in at 4%
2

Vectors are faster. Although for sequential iteration the fastest thing seems to be linked-lists.

Vectors can also be useful for bitmap operations (check out BitmapData.setVector, also BitmapData.lock and unlock).

Comments

1

The linked list example mentioned earlier in comments is incorrectly written though it skips odd nodes and because of that only iterates the half amount of the same data. No wonder he get so great results, might be faster with correct code as well, but not the same % difference. The loop sets current = current.next one time too much (both in the loop and as loop-condition) each iteration which cause that behavior.

Comments

0

According flash player penetration website it is a little higher. Around the 85%

This is the source

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.