I'm translating the C code to Delphi and ran into a performance issue on a specific piece:
Original:
| inline real32
Win32GetSecondsElapsed(LARGE_INTEGER Start, LARGE_INTEGER End)
{
real32 Result = ((real32)(End.QuadPart - Start.QuadPart) /
(real32)GlobalPerfCountFrequency);
return(Result);
}
|
My version:
| function Win32GetSecondsElapsed(Start, &End : LARGE_INTEGER): real32; inline;
begin
Result := (&End.QuadPart - Start.QuadPart) / GlobalPerfCountFrequency;
end;
|
After calling the sleep function there is this code to make sure that we hit the target frame rate:
| real32 TestSecondsElapsedForFrame = Win32GetSecondsElapsed(LastCounter, Win32GetWallClock());
Assert(TestSecondsElapsedForFrame < TargetSecondsPerFrame);
|
If I use the same code (Only that it's the Delphi version), I get an assert error.
If I change the code to this:
| TestSecondsElapsedForFrame := ((LastCounter.QuadPart - Win32GetWallClock().QuadPart) / GlobalPerfCountFrequency);
|
The error goes away, so the call to the function in Delphi takes long enough to push me over the time allowed for the sleep to complete.
Does anyone know how I can fix this?
I have tried changing the parameters in the Win32GetSecondsElapsed to be passed as pointers, but it did not help.
I thought it may be because it's being passed by value and a copy needs to be made, but that is not it.
I think that the 'inline' directive is not taking effect.