GML Arrays with (structed) arrays.. or one continued array?!

I wanted to know what would be best performance wise:

Code:
enum POINT {
   X = 0,
   Y,
   SIZE
}

p1 = [2, 4];
p2 = [3, 8];

//array of points
arr = [p1, p2];

//or continuous array
var i = 0;
arr[i + POINT.X] = 2;
arr[i + POINT.Y] = 4;
i+=POINT.SIZE;
arr[i + POINT.X] = 3;
arr[i + POINT.Y] = 8;

// if you want to access with method 1
var temp = arr[0];
var x = temp[POINT.X];

//with method 2 (where index is the point number)
var x = arr[ index * POINT.SIZE + POINT.X ];

//even with for loops

for (var i = 0; i < array_length_1d(arr); i += POINT.SIZE)
{
      arr[@ i + POINT.X] = 10;
      var a = arr[i + POINT.Y];
}
What do you think?!
 

jo-thijs

Member
I've not tested this, but I think it depends on how you use the arrays (how much, how local, resizing, writing, reading, iteration, ...).
I do think that in general, the continuous array will have slightly better performance though.
However, I also think that whatever performance difference there may be, it will be negligible.
To be sure though, you'll have to perform performance tests yourself.

Despite this all, I'd still recommend you to do yet something else: using 2D arrays!
They internally work like your first method, arrays in arrays, but they might be more optimized.
 
Top