View Full Version : my simple demos often cause CPU usage 100%,why?
gamefish
05-14-2005, 07:20 AM
...
UrbanLegend
05-14-2005, 08:25 AM
Overmind
05-14-2005, 09: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.
For a full-screen app, I think it is ok.
But, for a windowed app, I don't think it is always good.
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, 01: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.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.