Vector.<> vs array

余生颓废 提交于 2019-11-28 07:02:29

问题


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


回答1:


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.



回答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




回答3:


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).




回答4:


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.




回答5:


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

This is the source



来源:https://stackoverflow.com/questions/1130309/vector-vs-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!