Advertisement

Pointers & Multi-Dimensional Arrays

Started by March 01, 2001 10:17 PM
0 comments, last by Uncaged 23 years, 11 months ago
Hey all. I have a function that draws out a map. The map is stored in a multi-dimensional array such as Tiles[200][200]. My question is, how can I access that array with a pointer? Better yet, would it be more efficient to retrieve the information in a different way? Thanks,
Well, if all of the 200x200 items are adjacent in memory you can move through it with a pointer. I think it would be better to make it a single dimensional 40000 element array in memory though, then move through it like this:
  Tile *curtile = &alltiles[0];Tile *lasttile = &alltiles[(width*height)-1]+sizeof(Tile);while(curtile<lasttile) {  // Do stuff to curtile here  curtile++;}  



"Finger to spiritual emptiness underlying everything." -- How a C manual referred to a "pointer to void." --Things People Said
Resist Windows XP''s Invasive Production Activation Technology!
http://www.gdarchive.net/druidgames/

This topic is closed to new replies.

Advertisement