[Lazarus] Portable way to get accurate timestamps?

Sven Barth pascaldragon at googlemail.com
Sun Feb 27 18:06:13 CET 2011


On 27.02.2011 17:51, Graeme Geldenhuys wrote:
> On 26 February 2011 20:43, Marco van de Voort<marcov at stack.nl>  wrote:
>>
>> (1) this discussion is about a gettickcount implementation, but I'm not
>> entirely sure why this is needed so badly.
>
> I am by no means a libc expert, though I have tried myself to find a
> more fine-grained timing call under Linux. Windows (and I believe the
> GetTickCount implementation for Windows) uses the higher precision
> timing calls from the multimedia API. I can't confirmed this because
> I'm not at a computer with FPC source code - but from memory I think
> that is how it was done. The current linux version of GetTickCount is
> very rudimentary. As a few Google searches will show, many other
> developers are saying that using clock_gettime() under linux gives you
> the equivalent timing as the multimedia API under Windows.

I don't know whether you stuff the GetTickCount API call under 
"Multimedia API", but the GetTickCount implementation for Windows uses 
just that.

See this snippet from lcl/lclintf.pas:

=== source begin ===
{$IFDEF WINDOWS}

{$IFDEF MSWindows}
function GetTickCount:DWORD; stdcall; external 'kernel32.dll' name 
'GetTickCount';
{$ELSE}
function GetTickCount:DWORD; stdcall; external KernelDLL name 
'GetTickCount';
{$ENDIF}

{$ELSE}
function GetTickCount: DWord;
{$ENDIF}
=== source end ===

And GetTickCount uses the data provided by the Kernel for that (I don't 
know yet how the kernel calculates that data though...)

Regards,
Sven




More information about the Lazarus mailing list