CPU usage high

Does anyone have any tips on how to get my cpu usage down when drawing to a
sw surface with direct pixel drawing? On some games, I see the cpu usage
(from top) in the single digits, and in my program, it’s up around 30%, and
all my program does is every 50 miliseconds, I draw a random line segment.–

  • Mik Mifflin

Hi,

MM> Does anyone have any tips on how to get my cpu usage down when drawing to a
MM> sw surface with direct pixel drawing? On some games, I see the cpu usage
MM> (from top) in the single digits, and in my program, it’s up around 30%, and
MM> all my program does is every 50 miliseconds, I draw a random line segment.

Are you using SDL_Delay() in your program? If not, try that. That’ll
bring the CPU utilisation down… plus it’ll give chance for the OS to
breathe!

Neil.

Are you using SDL_Delay() in your program? If not, try that. That’ll
bring the CPU utilisation down… plus it’ll give chance for the OS to
breathe!

Sorry, should have posted more info. Every frame, I undraw the previous
line (draw a black line over it), draw a new line and then call
SDL_UpdateRect the all 0’s to update the screen. Then I call SDL_Delay and
wait until it’s time to do it again. What’s taking most of the cpu time
(my program takes less than 1%) are the calls to X. I’m not drawing more
than other programs that use vector graphics, and they get cpu usage in the
single numbers, and I can’t see if I’m doing anything different. I can
send source to anyone that wants to take a look.–

  • Mik Mifflin

Mik Mifflin wrote:

Sorry, should have posted more info. Every frame, I undraw the previous
line (draw a black line over it), draw a new line and then call
SDL_UpdateRect the all 0’s to update the screen. Then I call SDL_Delay and
wait until it’s time to do it again. What’s taking most of the cpu time
(my program takes less than 1%) are the calls to X.

I’m not drawing more
than other programs that use vector graphics, and they get cpu usage in the
single numbers, and I can’t see if I’m doing anything different. I can
send source to anyone that wants to take a look.

If you compare to XDrawLines() in Xlib, SDL is much less efficient for
vector graphics under X11 since it has to copy a huge pixel blocks, perhaps
the entire screen, instead of just the pixels that make up the lines.

What you can do is to be tighter in your update rectangles, and use
SDL_UpdateRects() with your knowledge of what areas you have changed.
Or switch to another video target such as dga or fbcon