« Return to Thread: CPU usage

Re: CPU usage

by Edward Byard :: Rate this Message:

Reply to Author | View in Thread

Some parts of this message have been removed. Learn more about Nabble's security policy.
I think I've sorted it.

I used to have a while (SDL_PollEvent) which is now an if (SDL_PollEvent) which handles the input,
and then put a 50ms delay outside this which brings the CPU down to 30%.

A bit more code re-organising and using a delay in some major animation work has got CPU usage down to
30% and made the system more stable and, it seems, the animation is much smoother.

Thanks for your advice!

Ed

----- Original Message ----
From: Alvin <alvinbeach@...>
To: sdl@...
Sent: Friday, 8 February, 2008 5:55:24 PM
Subject: Re: [SDL] CPU usage

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
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



Sent from Yahoo! - a smarter inbox.
_______________________________________________
SDL mailing list
SDL@...
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

 « Return to Thread: CPU usage