I am creating an application which must execute a function that takes too long (lets call it slowfunc()), which is a problem, since my application is working with a live video feed. By running this function every frame, the frame rate is severely affected.
Is there a way to run slowfunc() in the background without using threading? I don’t necessarily need it to run every frame, but every time it finishes, I’d like to examine the output. The only thing I can think of right now is to split up slowfunc() into several “mini-functions” which would each take approximately an equal amount of time, then run one minifunction per frame. However, slowfunc() is a relatively complex function, and I feel that there should be (hopefully is) a way to do this simply.
EDIT: I can’t use threading because this program will eventually be used on a tiny robot processor which probably will not support threading. I guess I can use “cooperative multitasking”. Thanks for your help!
Run it in a thread and after the calculation is finished, make the thread sleep until another calculation is ready to be run. That way you are not hit with the initialization of the thread every time.