跨平台C ++高精度事件计时器实现

编程入门 行业动态 更新时间:2024-10-11 01:12:14
本文介绍了跨平台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 ++高精度事件计时器实现

本文发布于:2023-11-06 08:44:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563217.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:计时器   事件   平台

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!