Sign in to follow this  

[SDL] how to conserve CPU cycles

Recommended Posts

homeboye    115
Hey, i'm working with SDLnet now and since i have a main loop it makes sense that CPU % is at 100%. But i'm asking if there is an alternative to main loops? btw, i'm using TCP protocol and the problem is in the server.

Share this post

Link to post
Share on other sites
evillive2    779
SDL_WaitEvent might help out in the case of an editor like the post above where you want the application to react to events instead of polling for them and do other things in the mean time. In the case of a server though depending on what kind of reaction time you are wanting SDL_Delay may be the right choice in that case.

Personally I would check if I have any current connections, if not then I would increase the delay to something close to 1 second since there is no real reason to update other than catching new connections. If I did then I would make the delay 0 or something small to cap the frame rate.

One thing of note though, I think SDL_Delay has different resolutions on different systems.
Note: Count on a delay granularity of at least 10 ms. Some platforms have shorter clock ticks but this is the most common.

Check the SDL_Delay documentation for more information.

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