Results 1 to 3 of 3

Thread: high Cpu usage with windows api

  1. #1
    Member Contributor
    Join Date
    Oct 2007
    Location
    persia,tabriz
    Posts
    71

    high Cpu usage with windows api

    hi

    my cpu usage for MS Windows application is too high ( about 50%)

    how can i decrease it?

    my code for handling events it: ( i belive problem is in this code)

    Code :
    #ifdef _WIN32
    MSG   msg;
    HWND m_hw = (HWND)m_Window->getHandle();
    while(!m_bDone)
    {
    if ( PeekMessage(&msg, m_hw, NULL, NULL, PM_REMOVE))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    else
    {
    // clearing screen
    m_Renderer->clear();
    // draw functions
     
    if ( m_Timer->getMilliSeconds() > 1000 )
    {
    m_uFps = m_uFrameCount ;
    m_uFrameCount = 0;
    m_Timer->Reset(); 
    std::cout << m_uFps  << std::endl;  
    }
    else
    {
    m_uFrameCount++;
    }
     
    // changing frame buffer
    m_Renderer->swapFramebuffer();
    }
    }
    #endif

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2007
    Location
    Latvia
    Posts
    225

    Re: high Cpu usage with windows api

    Well, you are calling code all the time while messages are unavailable. And if any code is executing, then CPU time is used. Nothing to wonder about.

    If you want CPU usage to be lower, then don't render anything for some time (put Sleep(1) affter swapFramebuffer() or enable vsync).

  3. #3
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: high Cpu usage with windows api

    Even better, only draw when needed, ie. with WM_PAINT messages.

Similar Threads

  1. OpenGL on Windows (high CPU usage)
    By johne53 in forum OpenGL: Windows
    Replies: 22
    Last Post: 01-18-2019, 05:25 AM
  2. High CPU usage when animating the object
    By openglam in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-04-2011, 12:34 AM
  3. CPU usage: How high is too high?
    By bucky in forum OpenGL: Windows
    Replies: 11
    Last Post: 01-13-2008, 09:27 AM
  4. Too high resource usage
    By hexa in forum OpenGL: Windows
    Replies: 2
    Last Post: 04-19-2007, 03:26 AM
  5. High CPU usage
    By Moshe Nissim in forum OpenGL: Linux
    Replies: 31
    Last Post: 08-24-2002, 07:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean