-
Question about arrays
There has been alot of talk about array's recently and it got me thinking.
Does a multidimensional array have any advantages/disadvantages over a non-multidimensional one?
Example:
to store things like tilemaps you could do
Or you could just
So in the end, does one method have any advantages over the other?
-
The computer treats multidimensional arrays as a single huge array. You are basically using pointer arithmatic to access the elements in the array either you single step by just incrementing through each element or you add an offset to increment by row or column etc. The main advantage is in the ease of use. It is alot easier to just access an array by its elements especially when you get to 3+ dimensions because the pointer aritmatic can get ugly and confusing.
-
Thank you,
I wasnt really sure how the computer dealt with them.