Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LARGE_INTEGER or TLargeInteger?

Tags:

delphi

In Windows.pas, there are:

  LARGE_INTEGER = record
    case Integer of
    0: (
      LowPart: DWORD;
      HighPart: Longint);
    1: (
      QuadPart: LONGLONG);
  end;

  TLargeInteger = Int64;

I see several Windows functions and structure members which is originally declared as LARGE_INTEGER has been translated to TLargeInteger such as:

  function QueryPerformanceCounter(var lpPerformanceCount: TLargeInteger): BOOL;
      stdcall;

and another example is:

  WIN32_STREAM_ID = record
    dwStreamId        : DWORD;
    dwStreamAttributes: DWORD;
    Size              : TLargeInteger;
    dwStreamNameSize  : DWORD;
    cStreamName       : array[0..0] of WCHAR;
  end;

Can TLargeInteger acts as a replacement of LARGE_INTEGER for every function parameters and structure members found in Windows header files?

like image 233
Astaroth Avatar asked Nov 20 '12 07:11

Astaroth


People also ask

What is a LARGE_INTEGER?

LARGE_INTEGER is a union of a 64-bit integer and a pair of 32-bit integers. If you want to perform 64-bit arithmetic on one you need to select the 64-bit int from inside the union.

What is LARGE_INTEGER QuadPart?

The LARGE_INTEGER structure is actually a union. If your compiler has built-in support for 64-bit integers, use the QuadPart member to store the 64-bit integer. Otherwise, use the LowPart and HighPart members to store the 64-bit integer.


1 Answers

You can always safely use these two types interchangeably in API translations. Although, clearly, once you have selected one type for a particular function, you have to stick to that type whenever you call that function.

  • Using TLargeInteger makes it easier to assign values because there's no need to refer to a record field.
  • Using LARGE_INTEGER makes it easier to separate into low and high 32 bit parts.

Now that the compiler has good support for 64 bit integers, it probably makes more sense to use TLargeInteger. Because, usually, there is no need to separate the 64 bit integer into its low and high parts. But way back when the compiler couldn't handle 64 bit integer types, there was no other option to work with 64 bit integers.

like image 142
David Heffernan Avatar answered Sep 19 '22 15:09

David Heffernan