Temple of The Roguelike Forums
Development => Programming => Topic started by: Anvilfolk on July 08, 2007, 05:12:35 PM
-
Right, so I've seen that a few people, instead of having a "real" matrix (as in, an array of arrays) use a single array, and when they want to access position (x, y) do something along the lines of array[x + y*width].
Is it really worth it? You're trying to trade two memory accesses for a single one with a little arithmetic on the side, right? Is that speed gain even significant?
Is there something I'm missing?
-
well its easier to malloc(x*y) than malloc(x) for(j=0;j<x; j++) x[j]=malloc(y)
accessing x[y][z] vs x[y*q + z] makes no difference.
it isnt about speed, its conveniance.
it really makes no difference.
-
Gotcha, thanks!
Having started to use it, it's also a bit more fool-proof than trying to remember to use matrix[y]- , which is still slightly counter-intuitive to me.