How to make application not hog the CPU power?
-
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!
-
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!
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
-
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!
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.
-
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!
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