QueryPerformanceFrequency/QueryPerformanceCounter

Started by
2 comments, last by Aerodactyl55 12 years, 1 month ago
MSDN says that the frequency cannot change while the system is running, but i have seen some claims that it does change. So is it safe to use them? And what are the other available options?
Advertisement
No, it doesn't change. It cannot change. It never changes while the system is running. People who claim it changes are not using it properly. You may safely rely on it.
(of course this is from a "normal operation" point of view. If you have hardware faults all bets are off, but that is extremely rare).

Other options are limited. The whole point of the QueryPerformanceCounter/Frequency functions is that they abstract away all the different processor speeds/power saving modes/different cores for you and always return a valid result. You could use GetTickCount (and all variants thereof) but their accuracy tends to break down around the 10ms mark. There's also probably a Unix/Linux equivalent for QPC/F but I have not looked into it.

Edit: also, it does not change while the system is running, i.e. it may change from one boot to the next and from one system to the next. This may seem like a tautology but you'd be surprised how many people stop reading at "cannot change" and try and recycle their frequency on multiple different systems. Then the same people cry foul at the documentation. dry.png

“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”

There were a few series of dodgey motherboards built a long time ago, where Win XP had a bug where the timer values could change, which completely breaks most games on those PC's. For people with these buggy computers, there is a WinXP patch to fix the issue.

So -- in general, the MSDN is right.
Technically, it's wrong, but only because of a few old bits of bad hardware (that break most games, not just yours), which can be fixed with a WinXP patch.
Thanks for replying. In fact i have been using them since and never had any problems with them. Only recently a found some claims on the internet that the frequency could change. I guess they forgot to mention that it affected only certain (buggy) motherboards.

This topic is closed to new replies.

Advertisement