CPU Time

Blitz3D Forums/Blitz3D Beginners Area/CPU Time

pc_tek(Posted 2009) [#1]
Is there a way to prevent a Blitz program from soaking all the CPU time up?

When I run the program in windowed mode, other windows apps get a little jerky.


Yasha(Posted 2009) [#2]
Yes. Take a look here: http://www.blitzbasic.com/Community/posts.php?topic=85370.


pc_tek(Posted 2009) [#3]
Cheers, Yasha!

Using that code has dropped the CPU time down to 29% from 50%


Kryzon(Posted 2009) [#4]
After seeing the Delay method Yasha suggested, isn't it the same as using CreateTimer(60)? (or 59, perhaps)

I tested the Delay way and it held the same result as using the timer functionality.


pc_tek(Posted 2009) [#5]
Strange...I altered the code to say 'Flip False' instead of 'Flip Limited'...and now the prgram only uses 2% of the CPU?

Is there something else going on here? Or is it too good to be true?


Kryzon(Posted 2009) [#6]
I have no idea!


Yasha(Posted 2009) [#7]
I have no idea how CreateTimer() compares to doing it this way (been years since I remembered CreateTimer() existed.... heh). It's probably simpler to use that if you don't intend to mix in some render-tweening later on.

"Limited" is just a true/false flag set higher up in the code, by the way (the idea being that this is one of those things you would want to be able to change in your settings menu). Anyway, the reason setting it to false reduces CPU load even further is because Flip True, as explained in the documentation, causes the program to wait for the vertical blank before continuing. Somehow it manages to do this without freeing any CPU time, despite the fact that Delay (and apparently WaitTimer()) do free CPU time. Anyway, the number of "spare" milliseconds counted by that particular code is always a whole number, while Flip necessarily has the ability to time things far more accurately than that, so you're still leaving some CPU time un-freed if you use Flip True (plus the code as given removes another millisecond for good measure in order to even out unexpected changes).