cpu hog!

Started by
3 comments, last by Shadowwoelf 16 years, 3 months ago
I was simply wondering how do I prevent my program from becoming a cpu hog? I am using the PeekMessage method and I cannot switch to get without irritating anyone who wants to use my program. Is there a way to just limit the program to update only 30fps? Thanks for the help
Advertisement
while (running){  process_messages();  if (time() < next_step)    Sleep(0);  else     do_next_step();}
Well, if your app is running in the foreground, it's perfectly acceptable to use 100% of the CPU. If nothing else is using the CPU, there's no problem. You could also change your process priority if you want to, but I don't think it's really worthwhile.

In my engine, I just do a busy loop with PeekMessage(), then Render() after all messages have been processed for a frame, and if the app gets minimised, it switches to GetMessage() and no rendering.
Quote:Original post by Evil Steve
You could also change your process priority if you want to, but I don't think it's really worthwhile.
I agree. I also tried this and found no real advantage. Today' scheduler is pretty smart even without those hints.

Previously "Krohm"

Well I understand that you can just use a loop to physically slow down the program but it would still use 100% cpu power, and since its a 2d rpg it doesn't need that much power.

Evil Steve, I will try your method asap so thanks.

This topic is closed to new replies.

Advertisement