+ 2

1D or 2D array?

In game programming what is better? Create coordinates in 2d or 1d array using this formula a[x+y*width] ?

28th Mar 2019, 5:46 PM
Lighton
Lighton - avatar
9 Antworten
+ 4
check which one has the least time complexity and use it
28th Mar 2019, 8:27 PM
Anon Fox
Anon Fox - avatar
+ 1
Well, it all depends upon your compiler that how it works. But using 2D array would be a better option ^_^
8th Apr 2019, 4:15 PM
Anshu Katyayan 💞
Anshu Katyayan  💞 - avatar
0
It depends on how often you access what variable. There are a lot of optimisation posibilities depending on the final usecase. You can look for caching optimisation of arrays.
28th Mar 2019, 5:55 PM
Dragonxiv
Dragonxiv - avatar
0
2D arrays are generally implemented as 1D arrays using your formula, so it makes no difference.
28th Mar 2019, 6:12 PM
Vlad Serbu
Vlad Serbu - avatar
0
but is it the same thing use the impementation of 2d array and creating it by yourself?
28th Mar 2019, 6:19 PM
Lighton
Lighton - avatar
0
I'm using java and I read the array every tick
28th Mar 2019, 7:24 PM
Lighton
Lighton - avatar
0
2d seems right🤔
30th Mar 2019, 5:13 PM
Python_dude
Python_dude - avatar