Pairs
From ActionScriptWiki
When storing multiple values together in one or more lists the best way is to use an object that holds all the information so there is no overhead for accessing multiple or the same list more than once.
[edit] Wrong Version
In this example audio samples with two normalized values are stored in a Vector.<T>. Each time a read and write operation happens the Vector.<T> has to be accessed four times.
const numSamples: int = 1024;
const numSamplesTimesTwo: int = numSamples << 1;
const samples: Vector.<Number> = new Vector.<Number>( numSamplesTimesTwo, true );
for( var i: int = 0; i < numSamplesTimesTwo; )
{
samples[ i++ ] = 0.0;
samples[ i++ ] = 0.0;
}
[edit] Correct Version
Using a class wich combines all properties into one object reduces the cost of a complete read write operation to only one Vector.<T> access for reading. Writing happens based on object properties. This makes also sense because such a structure allows you to keep the same object type in various data structures like a Vector.<T> and/or a LinkedList.
package
{
public final class Sample
{
public var left: Number = 0.0;
public var right: Number = 0.0;
}
}
const numSamples: int = 1024; const samples: Vector.<Sample> = new Vector.<Sample>( numSamples, true ); for( var i: int = 0; i < numSamples; ++i ) samples[ i ] = new Sample();

