c++ - Modern high res timer for periodic calls -
a huge amount has been said high resolution timers on stackoverflow. it's clear solution bit of moving target , best practices changing.
i need create high resolution timer has callback every 10ms achieve consistent 100hz. target platform windows 7 , later.
this exact question asked in 2009, believe things have moved on.
multimedia timers looked great solution, msdn says depreciated, replaced createtimerqueuetimer. other answers on stackoverflow suggest createtimerqueue timer not accurate timesetevent.
all answers consistently point out requirement setting windows timer resolution low value using timebeginperiod.
so said, best approach achieve above desired goal in c today.
but msdn says depreciated
it pretty important able read between lines when see deprecation warning this. yes, microsoft stop using multimedia timers. heavily abused , bad business. getting programmers stop using them pipe dream, createtimerqueuetimer() not alternative.
bad business because microsoft likes competitive in mobile computing. , multimedia timers poor match, murder on battery life. programs use them jack clock interrupt rate maximum allowed, 1000 times per second. backdoor 2000. , hard stop them doing that, when competitors give software away free. have no incentive whatsoever fix problem since makes mobile os good. , microsoft can't kill popular apps that.
microsoft also has mobile os, exposed through winrt api. deprecation rock-hard, cannot app approved store validation procedure when use timers. doesn't use, customers keep using desktop apps.
if want 100 hz update rate have use use timebeginperiod() , timesetevent(), there no other way. , avoid winrt. since 1.5 times worse default, there no appreciable reason worry power consumption. set laser stun , use works.
Comments
Post a Comment