20,741
edits
mNo edit summary |
No edit summary |
||
Line 8: | Line 8: | ||
In general, "loops" are not bad or expensive, it really depends on what you're doing inside the loop. | In general, "loops" are not bad or expensive, it really depends on what you're doing inside the loop. | ||
A loop will be executed within a single frame normally - so a long-running loop will add up to the frame spacing. | A loop will be executed within a single frame normally - so a long-running loop will add up to the frame spacing (the time needed to create a single frame). | ||
There's nothing magic about timers or listeners - they can just as well inflate your frame spacing. | There's nothing magic about timers or listeners - they can just as well inflate your frame spacing. | ||
It doesn't matter if the code/callback is run inside a loop, timer or a listener - what matter is the complexity of the code that runs. | |||
It doesn't matter if the code/callback is run inside a loop, timer or a listener - what does matter is the complexity of the code that runs. | |||
Timers or listeners are only really preferable over loops when it comes to checking for some condition, because polling is called "busy-waiting", i.e. more expensive, see the previous analogy. | |||
A listener or timer "waiting" is not resource-hungry, it's not even busy - it's not doing anything until it is "fired". | A listener or timer "waiting" is not resource-hungry, it's not even busy - it's not doing anything until it is "fired". | ||
Regarding {{func link|setprop()}}/{{func link|getprop()}} - they're not as bad as we used to think - in fact, Thorsten has shown that they're preferable over most [[Nasal library/props|props.nas APIs]], this may however change once the whole thing is replaced with [[Nasal/CppBind|cppbind bindings]]. | Regarding {{func link|setprop()}}/{{func link|getprop()}} - they're not as bad as we used to think - in fact, Thorsten has shown that they're preferable over most [[Nasal library/props|props.nas APIs]], this may however change once the whole thing is replaced with [[Nasal/CppBind|cppbind bindings]]. | ||
Thus, loops aren't bad necessarily: they can be used in a less-than-optimal manner, but there are often times where they make a lot of sense. Some pros and cons of both: | |||
Listeners: Pros: | Listeners: Pros: |