如何使用C ++在Windows上实现长期高分辨率定时? [英] How to realise long-term high-resolution timing on windows using C++?

查看:229
本文介绍了如何使用C ++在Windows上实现长期高分辨率定时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在很长一段时间(几个小时)内获得每几毫秒(20,30,40毫秒)的精确时间戳。采用时间戳的函数作为第三方库的回调调用。



使用 GetSystemTime()可以得到正确的系统时间戳,但只有毫秒的精度,为了我。使用 QueryPerformanceTimer()产生更准确的时间戳,但与长时间的系统时间戳不同步(请参阅 http://msdn.microsoft.com/en-us/magazine/cc163996.aspx )。



在上面链接的站点上提供的解决方案不知何故只能在较旧的计算机上工作,它在同步时挂起,当我尝试使用较新的计算机。



在我看来,boost似乎只有毫秒级的精度。
如果可能,我想避免使用外部库,但如果没有其他选择,我会用它。



有任何建议吗? p>

谢谢。

解决方案

从CodeProject删除的文章,这似乎是副本: DateTimePrecise C#类这个想法是使用 QueryPerformanceCounter API来获得精确的小增量,并定期调整它以保持长期精度。



另请参阅: Windows上的微秒分辨率时间戳


I need to get exact timestamps every couple of ms (20, 30, 40ms) over a long period of time (a couple of hours). The function in which the timestamp is taken is invoked as a callback by a 3rd-party library.

Using GetSystemTime() one can get the correct system timestamp but only with milliseconds accuracy, which is not precise enough for me. Using QueryPerformanceTimer() yields more accurate timestamps but is not synchronous to the system timestamp over a long period of time (see http://msdn.microsoft.com/en-us/magazine/cc163996.aspx).

The solution provided at the site linked above somehow works only on older computers, it hangs while synchronizing when i try to use it with newer computers.

It seems to me like boost is also only working on milliseconds accuracy. If possible, I'd like to avoid using external libraries, but if there's no other choice I'll go with it.

Any suggestions?

Thank you.

解决方案

Deleted article from CodeProject, this seems to be the copy: DateTimePrecise C# Class The idea is to use QueryPerformanceCounter API for accurate small increments and periodically adjust it in order to keep long term accuracy. This is about to give microsecond accuracy ("about" because it's still not exactly precise, but still quite usable).

See also: Micro Second resolution timestamps on windows

这篇关于如何使用C ++在Windows上实现长期高分辨率定时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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