[SDL] CPU usage
Edward Byard
e_byard at yahoo.co.uk
Fri Feb 8 12:08:27 PST 2008
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 at gmail.com>
To: sdl at lists.libsdl.org
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 at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20080208/9d12fdec/attachment.htm
More information about the SDL
mailing list