1D or 2D array? | Sololearn: Learn to code for FREE!


1D or 2D array?

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

3/28/2019 5:46:43 PM


9 Answers

New Answer


check which one has the least time complexity and use it


Well, it all depends upon your compiler that how it works. But using 2D array would be a better option ^_^


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.


2D arrays are generally implemented as 1D arrays using your formula, so it makes no difference.


but is it the same thing use the impementation of 2d array and creating it by yourself?


I'm using java and I read the array every tick


2d seems right🤔