CPU time in very basic win32 code

Started by
3 comments, last by DblStkSldr 20 years, 8 months ago
Why does the code below use 99% of the CPUs time in the task manager when an application like the first tutorial in the Direct3D section on two-kings.de simply runs idle taking up 0%? They are both simple applications that create a window and have a window procedure and message loop. I can''t pick out what is causing the difference. Thanks for any help.

  // Main message loop

  while (true)  {
    if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {

      if (msg.message == WM_QUIT)
        break;

      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }      
  }

  return msg.message;
Advertisement
while (true) {

James Simmons
MindEngine Development
http://medev.sourceforge.net
Sleep(1); will reduce the cpu usage... though its not really recommended. 99% cpu usage is fine for a game.
expanding on that, it''s smarter.

James Simmons
MindEngine Development
http://medev.sourceforge.net
Well, after an admittedly quick glance at the tutorial, their main loop uses GetMessage instead of PeekMessage. GetMessage blocks until there is a message to process, so your not really eating much processor time. PeekMessage returns immediately whether there was a message or not, so your loop is running continuously. But as the AP already noted, 99% for a game really isn't a big deal...

[edited by - rimtgd on July 27, 2003 2:04:09 AM]

This topic is closed to new replies.

Advertisement