my simple demos often cause CPU usage 100%,why?

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.


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.