跨平台C ++高精度事件计时器实现 [英] Cross platform C++ High Precision Event Timer implementation

查看:236
本文介绍了跨平台C ++高精度事件计时器实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自Windows平台,我通常使用Windows多媒体计时器来产生分辨率为1 ms + -1ms的定期回调。因此,我确实可以每秒产生1000个等距的回调。
为了在没有忙碌等待MS的情况下实现 的准确性,使用了高精度事件计时器,它直接访问硬件驱动程序。高精度计时器。但是我发现的只是Boost-ASIO计时器。由于他们根本不谈论精度,因此我认为他们将不能满足高精度要求。



所以..是否存在诸如高精度事件计时器的跨平台实现之类的东西?
还是Boost-ASIO足够精确?也许Boost内部使用了HPET,只是在任何地方都没有提及它。

解决方案

没有实现可以保证1ms分辨率的实现完整的Universe(PC,xbox,Android手机等)。所有实现都必须依靠操作系统来提供此分辨率,并且操作系统需要硬件支持。实现通常会提供较低分辨率的后备选项,不同硬件上的OS也会提供这种支持。



Boost(和新的C ++标准)提供了通用接口,但不能保证1ms。它们提供您可以在特定平台上获得的最好的东西。您可以在运行时获取有关分辨率的信息,然后拒绝运行。


Coming from the Windows platform I usually used the Windows Multimedia Timer to produce periodic callbacks with a resolution of 1 ms +-1ms. So I could indeed produce 1000 quite equidistant callbacks per second. To achieve this accuracy without doing busy-waiting MS used the High Precision Event Timer, which directly accesses a hardware driver.

I was hoping to find something like a boost library or so that provides a cross platform implementation for these kind of high precision timers. But all I found is the Boost-ASIO timers. Since they don't talk about precision at all, I'd assume that they won't meet the requirement a high precision. A jitter of 10ms would be way to much.

So.. is there something like a cross platform implementation of a High Precision Event Timer? Or might Boost-ASIO already be precise enough? Maybe Boost internally uses the HPET and just didn't mention it anywhere.

解决方案

There is no implementation that guarantees 1ms resolution across the full universe (PC, xbox, android mobiles, ...) . All implementations have to rely on the OS to provide this resolution and the OS needs hardware support. Implementations usually provide fallbacks to lower resolution and so do the OSes on different HW.

Boost (and new C++ standard) provide a generic interface but cannot guarantee 1ms. They provide the best you can get on the specific platform. You can get information about resolution at runtime and refuse to run.

这篇关于跨平台C ++高精度事件计时器实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆