[SDL] CPU usage

Alvin alvinbeach at gmail.com
Fri Feb 8 09:55:24 PST 2008


On Friday 08 February 2008 13:43:02 Edward Byard wrote:
> Hi
>
> My SDL app hogs the CPU unless in a state where I'm waiting for user input.
> Since I'm using SDL_PollEvent, I never miss an event, but CPU is at 100%
> the whole time.
>
> If I put a 100ms delay every pass of the loop, CPU drops to ~25% which is
> fine.
>
> So....how do I get CPU usage down to the ~25% figure without using a delay
> in the loop?
>
> This isn't a Windows app, just a console app.
>
> Any help muchly appreciated!
>
> Ed

It's hard to say without knowing how you are using SDL_PollEvent. If I had to 
guess, I say you are doing a spin-loop on it. In case you missed it, 
SDL_PollEvent returns right away regardless if events are in the queue. If 
you are constantly calling SDL_PollEvent, then I'd fully expect it to behave 
as you said.

Have a look at SDL_WaitEvent() and see if it fits into your program. If you 
aren't sure, can you post an example of how you read/poll the events?

Alvin


More information about the SDL mailing list