🔒 Locked
100% CPU infinite loop
Advertisement
Original Post
I suppose that your goal is something else: it would be easier for someone to answer if you describe your problem. I.e, should it be the main loop for an application? Which language? If you can set timers with callback functions, this could sometimes be a solution, or perhaps calling once a while sleep() in some enviroments (don't know really if it would save the cpu).
EDIT: ah, sorry, the replies were not displayed at first, so I thought there was none.
EDIT: ah, sorry, the replies were not displayed at first, so I thought there was none.
[assuming windows]
Another thing to do is that if you aren't going to be doing anything in your loop (eg, if your game has been minimized, and you're automatically paused it so you don't need to do any processing), use GetMessage instead of PeekMessage. GetMessage will let your application go to sleep until it gets sent a message, so the CPU can be given to other apps.
John B
Another thing to do is that if you aren't going to be doing anything in your loop (eg, if your game has been minimized, and you're automatically paused it so you don't need to do any processing), use GetMessage instead of PeekMessage. GetMessage will let your application go to sleep until it gets sent a message, so the CPU can be given to other apps.
John B
Quote:
Original post by Sneftel
Bad:while(true){ if(is_something_to_do()) { do_something(); }}
Better:while(true){ sleep_until_something_to_do(); do_something();}
If I was on my PC I would draw up a parody of the Animaniacs "Good Idea, Bad Idea"
Quote:
Original post by subflood
It was just to stop the CPU from going to 100% when the windows is not focused.
In that case, you should look for WM_ACTIVATE messages and act appropriately. You might also want call IsIconic() to find out if the window is minimized or not.
Quote:
Original post by JohnBolton Quote:
Original post by subflood
It was just to stop the CPU from going to 100% when the windows is not focused.
In that case, you should look for WM_ACTIVATE messages and act appropriately. You might also want call IsIconic() to find out if the window is minimized or not.
I'm using SDL
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement