Archived

This topic is now archived and is closed to further replies.

DblStkSldr

CPU time in very basic win32 code

Recommended Posts

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;

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Sleep(1); will reduce the cpu usage... though its not really recommended. 99% cpu usage is fine for a game.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites