> You can also use TDateTime, but if the clock on your computer is 
changed
> during time-measuring, you would get the wrong values.

Which is a very good reason for not using it!  And all the floating 
point arithmetic and conversion from system time is much slower. 

QueryPerformanceCounter can be used for periods longer than 49 days, 
but it's 64-bit arithmetic which I think is the FPU again.  Provided 
GetTickCount is used with functions that check for wrap around, and you 
don't want to measure more than 49 days, it's quite safe. And with a 
special function that allows the wrap around to be tested!

Angus

function DiffTicks (const StartTick, EndTick: longword): longword ;
begin
    if EndTick > StartTick then
        Result := EndTick - StartTick
    else
        Result := (MaxLongWord - StartTick) + EndTick ;
end ;
 
function GetTickCountX: longword ;
var
    newtick: Int64 ;
begin
    result := GetTickCount ;
    if TicksTestOffset = 0 then exit ;  // no testing, byebye

// TicksTestOffset is set in initialization so that the counter wraps 
// five mins after startup 
    newtick := Int64 (result) + Int64 (TicksTestOffset) ;
    if newtick >= MaxLongWrd then
        result := newtick - MaxLongWrd
    else
        result := newtick ;
end ;

// force GetTickCount wrap in 5 mins - next line normally commented out
TicksTestOffset := MaxLongWord - GetTickCount - (5 * 60 * 1000) ;

Angus
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to