Why do you want to reduce CPU usage? Take a look at Quake 3. It uses 100% CPU when it's not really doing anything. Most games do. This is a result of how their main loop works.Midnight wrote:So the question is, how can i reduce the cpu usage?
A really common "solution" to this "problem" is to put one or a few Sleep(0)s in your code. This gives up the remainder of your timeslice if there are other things scheduled to run. This gives other threads/processes the chance to run, resulting in smoother multi-tasking. If there are no other threads waiting to run, Sleep(0) doesn't have much effect. Either way, the CPU usage will stay at 100% -- your app will still eat as much as it can.
So what's the downside of having 100% CPU usage? Are you telling me that your processor isn't designed to run at 100%?
The correct way to deal with this is to write something more complicated than the typical main loop (i.e. while (1) { doWaitingEvents(); renderFrame(); }). For example, have one thread run the render loop actually taking desired frames per second into consideration, while another thread waits on UI input. This method has downsides, though. For example, it often doesn't look as smooth under any circumstances and certainly not on machines that are only marginally powerful enough.