I just made a breakthrough!

Published December 17, 2004
Advertisement
I finally found a use for pointers-to-pointers! See, right now I'm working on my tile engine, and one of the classes is cTileMap, which holds an array of the number of cTiles specified in the constructor. Now, each tile has an SDL_Surface* in them (obviously I'm using SDL), and I have a pointer to an area in memory (the tile array is being allocated on the heap). Anyway, the way I HAD been doing it was specifying each tile in the tile file, and loading them into each its own variable (which is now being turned into a much faster binary file), but now I just grab a pointer to each used tile and populate the array with pointers instead of actual tiles. So in essence I'm using a **SDL_Surface. I also use ** for traversal of a 2D array, since there would be no way to specify the Y value otherwise.

I never thought I could find a use for normal pointers, let alone pointers-to-pointers. I really feel like working on these projects alone is helping me learn C++ better. I also have to thank all the GDNers who helped my on my last tile-based endeavor, for showing me how I could just use the SDL_Surface* for the tiles instead of the bitmaps themselves (which wastes lots of memory).
0 likes 2 comments

Comments

Gaiiden
You don't really need to use a **. You could just use a regular *. I do the same thing for my game resources. I load an object (say an image object) and store the image on an SDL surface. If I want to duplicate that object, I create the new object but instead of loading the image again, I just point the second object's surface to the first object's surface. I don't use ** though. It's not any faster and it's just more confusing.
December 19, 2004 01:32 AM
Drakkcon
Well technically the SDL_Surface is a pointer, so pointing to it makes it a ** :).
December 19, 2004 01:44 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement

Latest Entries

..............

549 views

Untitled

954 views

Untitled

977 views

Back

971 views

I'm finally back

1006 views

Random updates

880 views

Hou zhou bu jien

907 views

Update

998 views
Advertisement