什么是 timeGetTime 的最佳替代品以避免环绕? [英] What's the best replacement for timeGetTime to avoid wrap-around?

查看:31
本文介绍了什么是 timeGetTime 的最佳替代品以避免环绕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

timeGetTime 似乎对查询系统时间.然而,它的返回值只有 32 位,所以它大约每 49 天回绕一次.

timeGetTime seems to be quite good to query for system time. However, its return value is 32-bit only, so it wraps around every 49 days approx.

检测调用代码中的翻转并不太难,但它增加了一些复杂性,并且(更糟糕的是)需要保持状态.

It's not too hard to detect the rollover in calling code, but it adds some complexity, and (worse) requires keeping a state.

是否可以替代 timeGetTime不会有这种环绕问题(可能通过返回 64 位值),并且具有大致相同的精度和成本?

Is there some replacement for timeGetTime that would not have this wrap-around problem (probably by returning a 64-bit value), and have roughly the same precision and cost?

推荐答案

不,跟踪翻转需要状态.它可以很简单,只需在每次回调时增加您自己的 64 位计数器即可.

Nope, tracking roll-over requires state. It can be as simple as just incrementing your own 64-bit counter on each callback.

想要以低至 1 毫秒的分辨率跟踪长达 49 天的时间段是非常不寻常的.您不得不担心经过这么长时间后精度仍然存在.下一步是使用时钟,GetTickCount(64)、GetSystemTimeAsFileTime 的分辨率为 15.625 毫秒,并通过时间服务器保持准确.

It is pretty unusual to want to track time periods to a resolution as low as 1 millisecond for up to 49 days. You'd have to worry that the accuracy is still there after such a long period. The next step is to use the clock, GetTickCount(64), GetSystemTimeAsFileTime have a resolution of 15.625 milliseconds and are kept accurate with a time server.

这篇关于什么是 timeGetTime 的最佳替代品以避免环绕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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