[Lazarus] Portable way to get accurate timestamps?

Luca Olivetti luca at wetron.es
Wed Feb 23 17:56:26 CET 2011


Al 23/02/11 13:17, En/na Petr Kristan ha escrit:
> On Sun, Feb 20, 2011 at 02:46:34PM +0100, Luca Olivetti wrote:
>> Al 20/02/11 12:42, En/na Bo Berglund ha escrit:
>>
>>> I wonder if GetTickCount will get me a better value to milliseconds
>>> than Now()?
>>
>> Not under linux:
>>
>> function GetTickCount: DWord;
>> begin
>>   Result := DWord(Trunc(Now * 24 * 60 * 60 * 1000));
>> end;     
> 
> My Linux version: 
> 
> function GetTickCount: Cardinal;
> var
>   ts: TTimeSpec;
>   i: Int64;
> begin
>   if clock_gettime(CLOCK_MONOTONIC, @ts) <> 0 then begin //kernels 2.4.* does not support

That's what I suggested a few messages ago (though I read somewhere that CLOCK_MONOTONIC
can drift, and there's a new, really monotonic, CLOCK_MONOTONIC_RAW), but that's not
the version in the lcl.
BTW: in which unit are clock_gettime and related constants defined?

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