Is there a reason to stick to Arrays as the default list data structure in AS3 if you are targeting Flash Player 10? Why not use Vectors (typed arrays) as default throughout your program since they are:
Does it perform badly or incur higher memory overheads? Any reason to use arrays anymore?
Plenty of reason. Vectors are not sparsely populated, for example, so that if your Vector has an index of 999, you have an array of 1,000 elements. In a standard Array, you could have as few as one.
I'm answering my own question based on what I learnt of the issue.
Vectors are faster for these datatypes ONLY: -- (proof)
Arrays are preferable for all other types:
Vectors are more limited to work with:
Vectors are more troublesome:
Vectors can be easier to debug:
Maybe specially when you don't know the type - it's a loosely based list, in a way. Like, say, with JSON data.
Edit: oh, here's another semi-reason - String.split()
. That'll return you an Array of strings. Dunno why you can't get a Vector.<String>
out of it, grr.
With that said, in Flash 10+, 99% of the time you'll be using Vectors instead. All 'disadvantages' of Vectors are just for very specific (often rare) use cases.
As Robusto already said, vectors are not sparsely populated. Although this might be bad for for size, it is very-very good for speed. So if you don't need very sparse populated structures (and that to implement that sparse thing also takes some extra space), you can just take advantage of the speed.
It is the typical trade-of: memory vs. speed :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With