Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to make application not hog the CPU power?

How to make application not hog the CPU power?

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Indrawati
    wrote on last edited by
    #1

    Hi Currently I am building an app that receives frame input from a camera and performs some computations on it. My problem is, my app is currently processing the frames as fast as possible, and that makes the computer's response very slow for other apps, i.e. my application work like this: while(app not closed) getinput(); processinput(); displayoutput(); end while Since this app may be run on a PC for hours and I don't want to disturb other apps' processing, is there a way for my app not to hog the CPU power while it's running, provided I can tolerate some drop in the frame rate? Thanks!

    M M R 3 Replies Last reply
    0
    • I Indrawati

      Hi Currently I am building an app that receives frame input from a camera and performs some computations on it. My problem is, my app is currently processing the frames as fast as possible, and that makes the computer's response very slow for other apps, i.e. my application work like this: while(app not closed) getinput(); processinput(); displayoutput(); end while Since this app may be run on a PC for hours and I don't want to disturb other apps' processing, is there a way for my app not to hog the CPU power while it's running, provided I can tolerate some drop in the frame rate? Thanks!

      M Offline
      M Offline
      Mike Beckerleg
      wrote on last edited by
      #2

      Perform the processing in a low priority thread. It will use all the CPU it can, but if a higher priority thread needs the processor it will get it. Mike

      1 Reply Last reply
      0
      • I Indrawati

        Hi Currently I am building an app that receives frame input from a camera and performs some computations on it. My problem is, my app is currently processing the frames as fast as possible, and that makes the computer's response very slow for other apps, i.e. my application work like this: while(app not closed) getinput(); processinput(); displayoutput(); end while Since this app may be run on a PC for hours and I don't want to disturb other apps' processing, is there a way for my app not to hog the CPU power while it's running, provided I can tolerate some drop in the frame rate? Thanks!

        M Offline
        M Offline
        Moak
        wrote on last edited by
        #3

        Indrawati wrote: while(app not closed) getinput(); processinput(); displayoutput(); end while make it (not so good)... while(app not closed)) { PollOnSomething(event) process() display() Sleep(0); } make it (better)... while(app not closed)) { WaitForSingleObject(event) process() display() } ...or better why not using normal windows messaging, post yourself a message e.g. WM_APP when "input" is available and handle it in a messange handler.

        1 Reply Last reply
        0
        • I Indrawati

          Hi Currently I am building an app that receives frame input from a camera and performs some computations on it. My problem is, my app is currently processing the frames as fast as possible, and that makes the computer's response very slow for other apps, i.e. my application work like this: while(app not closed) getinput(); processinput(); displayoutput(); end while Since this app may be run on a PC for hours and I don't want to disturb other apps' processing, is there a way for my app not to hog the CPU power while it's running, provided I can tolerate some drop in the frame rate? Thanks!

          R Offline
          R Offline
          Ravi Bhavnani
          wrote on last edited by
          #4

          As has been pointed out, running the loop in a separate thread is probably the best solution. If you don't want to use multiple threads, see the section "Responding to user input while performing a long task" in this[^] article. /ravi My new year's resolution: 2048 x 1536 Home | Articles | Freeware | Music ravib@ravib.com

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups