如何获得当前的Windows系统范围内的计时器分辨率 [英] How to get the current Windows system-wide timer resolution

查看:730
本文介绍了如何获得当前的Windows系统范围内的计时器分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,默认值是15.6 每个时钟毫秒,但有些失败者可能会改变它,然后来回换一次又一次,我需要轮询当前值是什么进行有效QueryPerformanceCounter的同步

那么,有没有一个API的方式,以得到定时器分辨率?

我在C ++ BTW。


解决方案

的Windows计时器的分辨率是由隐藏的API调用提供的:

  NTSTATUS NtQueryTimerResolution(OUT PULONG MinimumResolution,
                                OUT PULONG MaximumResolution,
                                OUT PULONG ActualResolution);

NtQueryTimerResolution是由本地的Windows NT库ntdll.dll输出。

通用硬件平台156,250报告或为100144的 ActualResolution 的;旧平台可能会报告甚至更大的数字;较新的系统中,当HPET(高precision事件定时器)或恒定/ TSC不变的支持格外,可能为ActualResolution返回156001。

拨打 timeBeginPeriod(N)反映在的 ActualResolution

更多细节这个答案

I know that the default is 15.6 ms per tick, but some loser may change it and then change back and forth again and again, and I need to poll what the current value is to perform valid QueryPerformanceCounter synchronization.

So is there an API way to get the timer resolution?

I'm on C++ BTW.

解决方案

Windows timer resolution is provided by the hidden API call:

NTSTATUS NtQueryTimerResolution(OUT PULONG MinimumResolution, 
                                OUT PULONG MaximumResolution, 
                                OUT PULONG ActualResolution);

NtQueryTimerResolution is exported by the native Windows NT library NTDLL.DLL.

Common hardware platforms report 156,250 or 100,144 for ActualResolution; older platforms may report even larger numbers; newer systems, particulary when HPET (High Precision Event Timer) or constant/invariant TSC are supported, may return 156,001 for ActualResolution.

Calls to timeBeginPeriod(n) are reflected in ActualResolution.

More details in this answer.

这篇关于如何获得当前的Windows系统范围内的计时器分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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