[Lazarus] Portable way to get accurate timestamps?

Luca Olivetti luca at wetron.es
Sat Feb 26 20:38:26 CET 2011


Al 26/02/11 19:43, En/na Marco van de Voort ha escrit:

> 
> (1) this discussion is about a gettickcount implementation, but I'm not
> entirely sure why this is needed so badly.

I use it extensively to keep track of time and
I can currently live with the workaround DWord(Trunc(Now * 24 * 60 * 60 * 1000))
but I have to put some safeguards since that is not monotonic.
Under windows I can be sure that the difference between GetTickCount and PreviousGetTickCount
will be positive (at least if I don't need to time events more than
24 days apart), under Linux I have no such guarantee.
So if, e.g. I have

function lapsed(origin:dword):dword;
begin
  result:=GetTickCount-origin;
end;

under windows I can do, eg


if lapsed(starttime)>5000 then
...
with no worries, while under linux I need
(to avoid waiting forever in case someone touches the system clock)


if (lapsed(starttime)>5000) or (lapsed(starttime)<0) then
...

which, apart from being quite inelegant, could fire well before 5 seconds have passed.

Bye
-- 
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004 (Ext.133)  Fax +34 93 5883007




More information about the Lazarus mailing list