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 :-)
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.