#### Archived

This topic is now archived and is closed to further replies.

# Multi verses single dimension arrays...

This topic is 5394 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

What is the point of a multi-dimensional array when the same thing can always be achieved using a single dimenional array? What I mean is this: int GameMap[100][100]; //can be replaced with int GameMap[100*100] Both achieve the same thing. As far as acessing goes: a=GameMap[x][y]; //as oposed to a=GameMap[y*100 + x]; Obviously the multi-dimensional array is easier to use when deling with many dimensions. And accessing the data in the single dimensional array will be slower because we have a multiplication and an adition as opposed just retrieving the data. Well I guess I have aswered my own question. Is there any other reasons that I am missing?

##### Share on other sites
Syntax, mainly. It's the same physical representation in memory, yet you get the convenience of using multiple indices. So if you were working with a grid, you could use X and Y coordinates.

I can't think of any other reasons off the top of my head besides syntax and convenience.

[edited by - Zipster on October 10, 2003 11:30:56 PM]

##### Share on other sites
Also, if you''re learning arrays, the multi-dimensional array is easier to learn. Myabe it''s just me, but when I first started the (y * 100 + x) messed me up on the linear arrays. Now that I know how to use them, that''s all I use.

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

##### Share on other sites
Well, I think it is best to have a dimention in the array for each dimention you are going to represent, because that way, you know which objects, belong to what, and how to get them easier. Because you don''t have to create some sort of weird mapping scheme to get at the points you need.

##### Share on other sites
Realloation of a multi-dimensional array is slower than reallocation of a single dimension array.

##### Share on other sites
The main difference is the type (which sounds pretty obvious, but it''s actually very important). In terms of typesafety, a 100 element array of some type is completely different from a multidimensional array of the same type and they can not (directly) be used interchangeably. A pointer or reference to a multidiemnsional array is not equivalent to a pointer or reference to a single-dimensional array with the same number of elements. They conceptually represent different things even though implementation-wise they can be exactly the same. The best parallel that I can give are points and vectors (mathematical vectors). A point represents a location, while a vector represents magnitude with direction. Both are represented using the same components. This does not, however, mean they are the same concept, they just share similar low-level components. Much the same, multidimensional arrays, while internally are the same as single-dimensional arrays, differ in concept.

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 28
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631737
• Total Posts
3001945
×