• Advertisement
Sign in to follow this  

[SDL] Why Pointers?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I don't fully understand pointers (and that's probably why I don't know the answer to this) but why are all SDL_Surface's pointers?

Share this post


Link to post
Share on other sites
Advertisement
One of the main resons could be performance. It's fairly common to have to pass a surface from one function to another. By using a pointer, only 32 bits (assuming a 32 bit architecture, like most computers) has to be moved about. When not using a pointer, BitDepthxPictureHeightxPictureWidth + some extra for other values in the surface has to be transfered. Even just a 256x256x32 picture will require moving over 2mb compared to 4 bytes for the pointer. Now imagine doing that a couple times each frame for each sprite in your game. It could add up pretty easily.

You could think of it as reading an entire article online to someone (not using pointers) compared to just telling them the URL of the article (using pointers).

Share this post


Link to post
Share on other sites
A SDL_Surface is a relatively large object, so making copys of it while passing it to functions or when returning it from functions may be expensive.

SDL_Surfaces are frequently modified by the functions you pass them too, so you would be passing them by pointer anyway.

Share this post


Link to post
Share on other sites
Pointer Zen:

When the mailman has to send you something, he doesn't build a house that looks just like yours, he uses the address of your one house, and that gets it to you :-).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement