What is the meaning of the ULARGE_INTEGER union?

http://msdn.microsoft.com/en-us/library/windows/desktop/aa383742%28v=vs.85%29.aspx

They are supposed to be used like this, set two 32-bit values ​​to LowPart and HighPart, and then perform arithmetic on QuadPart.

int a,b,c; ULARGE_INTEGER u; ... u.LowPart = a; u.HighPart = b; u.QuadPart += c; 

So, if you are going to do arithmetic on QuadPart (64 bit), in any case you need a 64-bit processor, right? So what's the point? Why not assign a value directly to QuadPart?

+4
source share
3 answers

You do not need a 64-bit processor to do arithmetic for a 64-bit data type. All 32-bit compilers that I know about support arithmetic for 64-bit integers. If the hardware does not allow you to use your own arithmetic, then the compiler must generate code to perform arithmetic. Usually this will use helper functions in the RTL compiler.

The structure is intended for use by compilers that do not provide native support for 64-bit data types. The documentation you refer to itself makes this clear:

Note Your C compiler may support 64-bit integers natively. For example, Microsoft Visual C ++ supports the integer type __ int64 . For more information, see the documentation that came with your C compiler.

Compilers that do not support native 64-bit integers cannot process a QUADPART member as an integer.

 typedef union _ULARGE_INTEGER { struct { DWORD LowPart; DWORD HighPart; }; struct { DWORD LowPart; DWORD HighPart; } u; ULONGLONG QuadPart; } ULARGE_INTEGER, *PULARGE_INTEGER; 

And the definition of ULONGLONG :

 #if !defined(_M_IX86) typedef unsigned __int64 ULONGLONG; #else typedef double ULONGLONG; #endif 

Of course, all compilers written in the last 10 years (or more) will have built-in support for 64-bit integers. But this union was originally introduced a very long time ago, and then the landscape of the compiler would be different. When viewing Windows header files, always remember the history and legacy.

+7
source

Typically, ULARGE_INTEGER used when you need to convert a pair of 32-bit integers to a 64-bit integer or vice versa.

For example, consider managing the FILETIME structure:

 void add_millisecond(FILETIME * ft) { ULARGE_INTEGER uli; uli.LowPart = ft->dwLowDateTime; uli.HighPart = ft->dwHighDateTime; uli.QuadPart += 10000; ft->dwLowDateTime = uli.LowPart; ft->dwHighDateTime = uli.HighPart; } 

You cannot assign a QuadPart value directly because you do not have it; all you have is the high and low parts.

+4
source

So, if you are going to do arithmetic on QuadPart (64 bit) anyway you need a 64-bit processor, right?

No. But the real question should be, do you need a compiler that supports a 64-bit integer type? The answer to this, too, is no. What are these functions for?

http://msdn.microsoft.com/en-us/library/windows/desktop/aa383711%28v=vs.85%29.aspx

+3
source

All Articles