Pairs

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.

Wrong Version
In this example audio samples with two normalized values are stored in a Vector.. Each time a read and write operation happens the Vector. has to be accessed four times.

const numSamples: int = 1024; const numSamplesTimesTwo: int = numSamples << 1; const samples: Vector. = new Vector.( numSamplesTimesTwo, true ); for( var i: int = 0; i < numSamplesTimesTwo; ) { 	samples[ i++ ] = 0.0; samples[ i++ ] = 0.0; }

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. 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. 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. = new Vector.( numSamples, true ); for( var i: int = 0; i < numSamples; ++i ) samples[ i ] = new Sample;