Reputation: 113996
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?
Upvotes: 5
Views: 766
Reputation: 113996
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:
Upvotes: 4
Reputation: 76
It just depends on what you're trying to do. Try sorting a Vector? It'll take much longer. Are you going to need to splice an array or vector? In which case, you'd probably want to ditch them both and use a linked list. If you're looking for something with named keys that you need to reference, then you'd probably use a Dictionary instead. It's a vague, useless answer--"it depends"--but it really does. There's a reason why there are so many different data list structures.
Upvotes: 1
Reputation: 5787
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 :-)
Upvotes: 1
Reputation: 10659
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.
Upvotes: 2
Reputation: 31883
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.
Upvotes: 5