Vector.<> vs array
Asked Answered
N

5

15

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

Neysa answered 15/7, 2009 at 9:20 Comment(1)
As a side note, this should be tagged flex4 flashplayer10.Prostomium
T
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.
Tempera answered 15/7, 2009 at 9:41 Comment(3)
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-1802Neysa
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.Prostomium
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.Tempera
N
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

Nureyev answered 15/7, 2009 at 12:34 Comment(1)
At the time of this comment, the non-detected version + flash 9 clocks in at 4%Foucquet
M
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).

Musgrave answered 23/7, 2009 at 10:20 Comment(0)
D
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.

Dipteran answered 12/8, 2009 at 8:36 Comment(0)
T
0

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

This is the source

Tempera answered 15/7, 2009 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.