Delphi-PRAXiS
Seite 1 von 3  1 23      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   Windows.GetTickCount64 auch unter Windows XP? (https://www.delphipraxis.net/194048-windows-gettickcount64-auch-unter-windows-xp.html)

Glados 11. Okt 2017 10:41

Windows.GetTickCount64 auch unter Windows XP?
 
Heute habe ich das erste mal von Windows.GetTickCount64 gehört. Kann man das auch unter Windows XP nutzen oder benötigt man für Windows XP diesen Workaround?
http://www.delphipraxis.net/711170-post5.html

himitsu 11. Okt 2017 11:18

AW: Windows.GetTickCount64 auch unter Windows XP?
 
Was steht dort MSDN-Library durchsuchenGetTickCount64 in den "Requirements"? :zwinker:

Also ja, vor Windows 8 gibt es das nicht und man braucht was Anderes.

Glados 11. Okt 2017 11:47

AW: Windows.GetTickCount64 auch unter Windows XP?
 
Heißt also das Andere ist dein Code da oben? :P

Braucht man denn irgendwelche Fallunterscheidungen je nach Betriebssystem oder kann man einfach die Unit oben nutzen?

Wenn ich das hier richtig verstehe sollte das doch schon als "Fallunterscheidung" reichen
Delphi-Quellcode:
GetTickCount64 := GetProcAddress(GetModuleHandle('Kernel32.dll'), 'GetTickCount64'); // Für alles ab Windows 8
if @GetTickCount64 = nil then // für alles vor Windows 8
 //

himitsu 11. Okt 2017 11:56

AW: Windows.GetTickCount64 auch unter Windows XP?
 
Jupp, entweder die WinAPI oder wenn nicht existent, dann wird automatisch die Ersatzfunktion verwendet.

Zacherl 11. Okt 2017 12:05

AW: Windows.GetTickCount64 auch unter Windows XP?
 
Hier gibt es dazu noch einen Artikel mit Workarounds:
http://terryto-blog.tumblr.com/post/...4-alternatives

Glados 11. Okt 2017 12:50

AW: Windows.GetTickCount64 auch unter Windows XP?
 
Zacherl, dein Artikel hat mich neugierig gemacht und die Schnelligkeit von _GetTickCount64 geprüft.

bei 999.999 aufrufen dauert die Ausführung schon knapp 400ms. Windows.GetTickCount54 braucht nur knapp 25ms.

Zacherl 11. Okt 2017 13:30

AW: Windows.GetTickCount64 auch unter Windows XP?
 
Welche der Versionen hast du denn verwendet? Die mit dem manuellen Overflow Check sollte die Performance nicht nennenswert verschlechtern (laut Artikel ist sie ja angablich sogar besser als die native MSDN-Library durchsuchenGetTickCount64 API).

Glados 11. Okt 2017 13:34

AW: Windows.GetTickCount64 auch unter Windows XP?
 
Ich habe himitu's Version (Link erster Beitrag) verwendet. Mit den anderen kann ich nichts anfangen, da es kein Delphi-Code ist.

Mehr als das hier bekomme ich nicht hin und selbst das ist bestimmt noch falsch
Delphi-Quellcode:
var
 high, lastLow: Int64;
begin
 high := 0;
 low := GetTickCount();

 if lastLow > low then
  // high += 0x100000000I64; ...

 lastLow = low;

 // return high | (ULONGLONG)low;
end;

Zacherl 11. Okt 2017 13:44

AW: Windows.GetTickCount64 auch unter Windows XP?
 
Sollte in etwa so aussehen:
Delphi-Quellcode:
threadvar
  High: UInt64;
  LastLow: Cardinal;

function _GetTickCount64: UInt64; inline;
var
  Low: Cardinal;
begin
  Low := GetTickCount;
  if (LastLow > Low) then
  begin
    High := High + $0000000100000000;
  end;
  LastLow := Low;
  Result := High or Low;
end;
Ist etwas weniger als halb so performant wie die native Funktion, aber immer noch deutlich schneller als mit MSDN-Library durchsuchenQueryPerformanceCounter. Wenn du garantiert nur einen Thread hast, kannst du das
Delphi-Quellcode:
threadvar
auch durch
Delphi-Quellcode:
var
ersetzen - dann ist die Funktion in etwa gleich schnell wie die native Variante.

Glados 11. Okt 2017 14:07

AW: Windows.GetTickCount64 auch unter Windows XP?
 
Ich habe das jetzt so gelößt

Delphi-Quellcode:
unit uGetTickCount64;

interface

uses
 Winapi.Windows, System.SysUtils;

threadvar High: UInt64;
LastLow:
Cardinal;

type
 TGetTickCount = class
 public
  class function GetTickCount64: UInt64; inline;
 end;

implementation

class function TGetTickCount.GetTickCount64: UInt64;
var
 Low: Cardinal;
begin
 if System.SysUtils.TOSVersion.Major >= 6 then // alles ab Windows Vista
  Result := Winapi.Windows.GetTickCount64
 else // alles vor Windows Vista
  begin
   Low := GetTickCount;
   if (LastLow > Low) then
    High := High + $0000000100000000;

   LastLow := Low;
   Result := High or Low;
  end;
end;

end.


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:19 Uhr.
Seite 1 von 3  1 23      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz