I was sure this question has been asked before so I did of course use the search function to check if there's an answer solving my issue.
However, all I could find were a lot of answers on measuring time in high precision.
What I would need is a high resolution (at least millisecond) timer which allows me to fire a callback when a defined time period passed. I'd like to use that in a Cocoa Mac OS X app, so C/C++ or Obj-C would be possible. If additional libraries are needed, then this is fine, too.
I found this http://www.songho.ca/misc/timer/timer.html but it's using a busy waiting strategy and would cost too much performance I assume.
Help is greatly appreciated!
One great technology you can use comes directly from Apple. Timer dispatch sources:
http://developer.apple.com/library/mac/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/GCDWorkQueues/GCDWorkQueues.html
It will take a while to read that, but once you get it, it's quite easy to use. You can specify the time interval in nanoseconds, and the block that should be periodically executed.
It's a part of the GCD technology, and it's C based. Since Objective-C is just C plus some additions, it seems more natural to just stick to C. Going into C++ and thus Objective-C++ seems like an overkill in this case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With