Sign in to follow this  
Uphoreum

[SDL] Why Pointers?

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this