Quick Tip: Multi-Dimensional Vectors

Have you ever thought of creating or using multi-dimensional Vector in ActionScript? Yes, it is possible and the definition syntax comes pretty logical to me now ;-).

var list:Vector.<Vector.<int>> = new Vector.<Vector.<int>>();

…or shorter declaration:

var list:Vector.<Vector.<int>> = new <Vector.<int>>[];

now your vectors have two dimensions, I mean:

list[0][0]

Pixel Bender Inputs – Vector or ByteArray

Pixel Bender for Flash Player lets you play some more advanced games. Based on your needs you can force your kernels to “eat” not only BitmapData, but also ByteArray-s or Vector-s. With this knowledge, you can simply use Pixel Bender kernels for some fast math or processing like 3D engines (3D to 2D projection) etc. Lets have a look at some simple demos, how to push vector and raw bytes directly into shader via ShaderJob:

Read the rest of this entry »

Myth Buster – Benchmarking Loops

Lets have a look at some of the most common and fastest loops used in ActionScript 3. Is int really faster than uint and Number? Is while loop faster than for? Is pre-increment faster than post-increment? To test all of these I have created benchmark test application on wonderfl. App compares loops with 10.000.000 iterations and logs testing times. To compare different variable types, loop methods, increment / decrement modes, there are buttons grouping each test. Please be patient with your first click, the model Array is being generated (Link button also generates linked list). The first test compares Arrays, second one Vectors.

Read the rest of this entry »

Quick tip: Array vs. Vector

Take a closer look at the ActionScript 3 memory consumption, when stored huge amount of values in Vector and Array. First list of uints:

(10000000 / 32) uints in a Vector (10000000 bits) = ~7k
(10000000 / 32) uints in an Array (10000000 bits) = ~1228k

… and list of Booleans:

10000000 Booleans in a Vector = ~8k
10000000 Booleans in an Array = ~39070k

Read more about AVM2 Memory Considerations.