PDA

View Full Version : my simple demos often cause CPU usage 100%,why?



gamefish
05-14-2005, 08:20 AM
...

UrbanLegend
05-14-2005, 09:25 AM

Overmind
05-14-2005, 10:05 AM
Most code frameworks use a "render as many frames as possible" scheme. This means that either a part of the GPU pipeline or the CPU will always run at 100%. This is expected behaviour and nothing to worry about.

05-14-2005, 05:10 PM
For a full-screen app, I think it is ok.
But, for a windowed app, I don't think it is always good.

05-17-2005, 12:27 AM
Insert a 1ms delay somewhere in the loop of your code. This will drasticly reduce cpu usage and makes almost no difference in game performance.

Mark

Relic
05-17-2005, 02:14 AM
Most of the simple tutorials put their rendering calls into the idle loop. This is "game style".
If you don't need that, write a standard window message handler and do the drawing inside the WM_PAINT handler and you won't use any CPU cycles if your demo doesn't need to react on paint messages.
If you want it animated, setup a timer with SetTimer() and a WM_TIMER message handler calling InvalidateRect() which sends WM_PAINT messages to your handler.
Very clean, but not to be used for fullspeed or benchmarks.