Sign in to follow this  
SigmaX

SDL and a lot of surfaces. Performance issues?

Recommended Posts

Hey, I'm working on a menu based application using SDL and C++ in Linux. I am creating multiple screens, which will have buttons. I used the same button so I only have to load one image. Also the buttons will only be in specific locations so each sceen will use the same SDL_Rect to position the buttons. I put the text on the buttons after the fact using SDL_ttf. What I am planning on doing is creating surfaces for each button when the app starts, and just blitting the ones I need to the screen when I need them. I'm wondering if there would be a performance issue for creating and keeping a lot of text surfaces. (probably 100+) I will also be creating and SDL_Rect for each surface. Clear as mud? Good!

Share this post


Link to post
Share on other sites
If your text surfaces would all have the smae font, size and colour, you could create one surface that has all the letters on it, and use the SDL_Rect trick to pick out the ones you want.

Its a bit more complicated than having a unique surface per string, but if you find performance is affected the other way, you could try that.

Share this post


Link to post
Share on other sites
SDL_Surfaces are just using up memory if they aren't being drawn. Depending on your color depth, surface dimensions, etc. they'll take up different amounts of memory, but I think it unlikely that you'll have serious problems if you load them all at startup. You might run into issues with drawing many surfaces to the screen; is that what you're concerned about? In any event, I wouldn't worry too much about performance unless you're actually running into slowdown. Premature optimization is frequently pointless, as you find that the area you anticipated being a bottleneck is just fine, while some random function on the other side of the program is eating up half your CPU.

Share this post


Link to post
Share on other sites
You should be OK with hanging onto that many surfaces provided you have the memory for it. If you don't have the memory for it, you may experience performance hits from all the swapping you'll need to get them back into system RAM.

TBH, I just redrew my text every frame when I was using SDL_ttf and didn't notice a significant performance hit. Just make sure to free the surface if you do it that way, otherwise you'll get a big memory leak. [wink]

Share this post


Link to post
Share on other sites
Quote:
Original post by Ravuya
TBH, I just redrew my text every frame when I was using SDL_ttf and didn't notice a significant performance hit. Just make sure to free the surface if you do it that way, otherwise you'll get a big memory leak. [wink]


I agree with this completely. Especially for a menu based application, it should not be a problem, and will be much simpler.

Share this post


Link to post
Share on other sites
Thank you very much for all your responces. I think the real meat of my question was, would I have performance issues with a bunch of non active (but initalized) surfaces lying around. I think I now have a good answer.

Of course now I've decided not to do it that way, mainly for a managment stand point. That would be a lot of different varaiables to keep track of. Even still, I had been curious about that for a little while now. SO thank you. [cool]

Oh and that reminds me, I need to free my surfaces! [looksaround]

Share this post


Link to post
Share on other sites
Quote:
Original post by SigmaXOh and that reminds me, I need to free my surfaces! [looksaround]
Be glad you remembered this now, and not when you realized that you had a 1MB/sec memory leak!

(Turns out that I was recreating each surface each frame, because of rotozooming, and I was failing to free the rotozoomed copies; oops).

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