[fpc-pascal] The unfortunate deprecation of GetTickCount
alex at dcclost.com
Wed Apr 11 18:26:37 CEST 2018
The documentation seems fine. I can use it to approximate that a minute
has elapsed, or to keep track of frames per second for a game, but I'm
not going to use it to control complex machinery.
The GetTickCount documentation offers that most system timers are within
the 10 to 16 millisecond range. So if windows (internally) updates
GetTickCount every millisecond, it's count might look like this from boot:
- 10 more times
- maybe 9 more times
- maybe 8 or 9 more times
So in this example, if you want to time something to happen EXACTLY
every 10 milliseconds, you'd miss 10ms by 4, 20ms by 7, and you'd skip 30ms.
This is why you do stuff like:
if (gettickcount - previous) > 10 then /* do something here */
A solution for the gettickcount overflow I liked was something like:
if (current >= previous) then
elapsed:=current - previous
elapsed:=(high(dword) - previous) + current;
if (elapsed > ...)
On 04/11/2018 09:40 AM, Paulo Costa wrote:
> Unfortunate is the obscure wording you find on the documentation:
> GetTickCount returns an increasing clock tick count. It is useful for
> time measurements, but no assumtions should be made as to the interval
> between the ticks. This function is provided for Delphi compatibility,
> use GetTickCount64 instead."
> One would think that GetTickCount64 would clarify things about the
> interval between the ticks (just to be useful for time measurements) but:
> GetTickCount64 returns an increasing clock tick count. It is useful
> for time measurements, but no assumtions should be made as to the
> interval between the ticks."
> How can it be useful for time measurements if we don't know the units?
> Contrast to the Microsoft Documentation:
> "Return value
> The return value is the number of milliseconds that have elapsed since
> the system was started."
> Of course, it is followed by some remarks about the real limitations
> but at least we have some idea on what to expect.
> I know that, by being cross platform, GetTickCount64 can behave in
> different ways on other environments but, just because of that, the
> user should not be kept in the dark when using it.
> I know that the documentation effort is hard and many times we don't
> appreciate the effort as we should, but please don't be so vague on
> this entry.
> Paulo Costa
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
More information about the fpc-pascal