Does it matter what order a grid is created in the create event?

flyinian

Member
Instead of going 0,1,2,3,4... Could it be done 2,4,1,0,3?

GML:
Would this still work?
Any where in the grid? any x or y position?


ds_grid_add(name,0,1,value);
ds_grid_add(name,0,4,value);
ds_grid_add(name,0,0,value);
ds_grid_add(name,0,3,value);
ds_grid_add(name,0,2,value);


compared to ,

ds_grid_add(name,0,0,value);
ds_grid_add(name,0,1,value);
ds_grid_add(name,0,2,value);
ds_grid_add(name,0,3,value);
ds_grid_add(name,0,4,value);
 

TheouAegis

Member
For a grid, no. When you create the grid, you define its size, which means the memory is already allocated in advance.

For a 2D array, it potentially makes a difference. Supposedly memory for arrays is alloted in increments, so some array sizes use the same amount of memory even if they're not the same size (e.g., an array 5 indexes long might be the same size as an array 7 indexes long. It would then follow that if you initialize index 5 in the array and then initialize index 9, which would be the next increment, GM would have to pause a moment to allocate more memory. The max array index is 31999, so if you actually needed an array larger than 32000 indexes, it wouldn't matter if you set 31999 before you set 49999 because the two indexes technically belong to separate arrays; but you would want to set 49999 before you set 33000.

But back to your actual question, no, it doesn't matter.
 

flyinian

Member
For a grid, no. When you create the grid, you define its size, which means the memory is already allocated in advance.

For a 2D array, it potentially makes a difference. Supposedly memory for arrays is alloted in increments, so some array sizes use the same amount of memory even if they're not the same size (e.g., an array 5 indexes long might be the same size as an array 7 indexes long. It would then follow that if you initialize index 5 in the array and then initialize index 9, which would be the next increment, GM would have to pause a moment to allocate more memory. The max array index is 31999, so if you actually needed an array larger than 32000 indexes, it wouldn't matter if you set 31999 before you set 49999 because the two indexes technically belong to separate arrays; but you would want to set 49999 before you set 33000.

But back to your actual question, no, it doesn't matter.
Awesome, Thank You.
 
Top