AS3 数组向量 [英] AS3 Vector of Arrays

查看:19
本文介绍了AS3 数组向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将数组存储在数组类型的向量中是否有任何性能优势?

Is there any performance benefit in storing Arrays in a Vector of type Array?

例如选项 1

private var _arrays:Vector.<Array> =  new Vector.<Array>(2); 
_arrays[0] = new Array(10);
_arrays[1] = new Array(10);

选项 2

private var _arrays:Array =  new Array(2); 
_arrays[0] = new Array(10);
_arrays[1] = new Array(10);

我也可以有一个或多个向量吗?

Also can I have a Vector or Vectors?

 private var _vectors:Vector.<Vector> = new Vector.<Vector>(2);

_vectors[0] = new Vector.<String>(10);
_vectors[1] = new Vector.<String>(10);

谢谢,

标记

推荐答案

EDIT

除了最后一部分,我原来的回答是错误的,我必须为此道歉.我知道 Vector 在幕后"正好有四个实现.(您可以在 Robert Penner 此处的帖子中找到来自 FP 10 playerglobal.swc 的反编译源代码)其中三个用于数字类型(int、uint 和 Number).一种是用于对象类型.最后一个作为一个包罗万象的工具,包含从 Object 派生的所有类.这就是为什么我认为 Vector. 仍然比 Array 快,依赖于 Adobe 提供的有关向量和数组的信息.

My original answer was wrong except for the very last part, and I have to apologize for that. I knew for a fact that Vector has exactly four implementations "under the hood". (You can find decompiled sources from FP 10 playerglobal.swc in a post by Robert Penner here) Three of those are for number types (int, uint and Number). One is for Object types. This last one serves as a catch-all and takes in all classes derived from Object. This is why I assumed that Vector.<Object> was still faster than Array, relying on the information regarding vectors and arrays available from Adobe.

然而,这个信息似乎是错误的,或者至少遗漏了一些重要的部分:

However, it seems that this information is wrong, or at least it leaves out some important parts:

  1. 虽然 Vector.<AnyClassDerivedFromObject> 允许严格类型化,但此类型信息仅在编译时评估(因此您获得更多类型安全性),而不是在运行时评估 - 因此本质上严格键入对象向量的好处不适用于性能.请参阅这篇博文了解更多信息.

  1. While Vector.<AnyClassDerivedFromObject> allows for strict typing, this type information is only evaluated at compilation time (so you get more type safety), but not at runtime - thus essentially the benefits of strict typing object vectors do not apply to performance. See this blog post for more info.

因此,唯一比数组更快的 Vector 实现是数字类型 (!).

Consequently, the only implementations of Vector that are faster than Array are the ones for number types (!).

事实上,我对此做了一些广泛的测试,并得出结论,虽然 Vector. 比整数数组快 60%,但所有的派生Vector. 不仅速度相等(即 Vector.Vector. 的表现相同code>,它们也比 Array 约 20%.我已经对此进行了两次和三次检查,因此我相信结果相当准确.

In fact, I have done some extensive testing on this, and have come to the conclusion that while Vector.<int>is up to 60% faster than Array of ints, all the derivates of Vector.<Object> are not only equal in speed (i.e. Vector.<Object> performs the same as Vector.<String>, they also are about 20% slower than Array. I've double- and triple-checked this, so I believe the results to be fairly accurate.

数字类型向量更快,这仍然是事实,因此您应该使用它们来获得优于 Array 的性能优势.但是:

It still is true that the number type vectors are faster, so you should use those for performance benefits over Array. But:

结束编辑

仅当您打算使用 sort()sortOn() 或任何其他方便的 Array 排序函数时,您仍可能会做出其他决定,因为这些是本机函数,因此非常很快.在 Vector 上实现您自己的排序方法可能与它们的速度不匹配.

Only if you're going to use sort(), sortOn() or any other of the convenient sorting functions of Array, you might still decide otherwise, because these are native functions, and as such really fast. Implementing your own sorting methods on a Vector will probably not match their speed.

这篇关于AS3 数组向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆