了解 OVERLAPPED 结构中的偏移字段
Understanding the offset fields in the OVERLAPPED structure
我正在查看一些使用 ReadFile
并指定 OVERLAPPED
类型的代码。
根据我目前阅读其他帖子的理解,这就是我得到的。
如果您想在文件的第 8 个字节开始一个 ReadFile
,您可以将 OVERLAPPED
的 Offset
变量设置为 8,并将 OffsetHigh
变量设置为在将 OVERLAPPED
传递给 ReadFile
之前为 0。这是有道理的。
现在,如果我们将 OffsetHigh
设置为 1 会怎样?
实际偏移量是一个64位整数。 Offset
字段为低32位,OffsetHigh
字段为高32位。 documentation:
Offset
The low-order portion of the file position at which to start the I/O request, as specified by the user.
...
OffsetHigh
The high-order portion of the file position at which to start the I/O request, as specified by the user.
...
The Offset
and OffsetHigh
members together represent a 64-bit file position. It is a byte offset from the start of the file or file-like device, and it is specified by the user; the system will not modify these values. The calling process must set this member before passing the OVERLAPPED
structure to functions that use an offset, such as the ReadFile
or WriteFile
(and related) functions.
这种 low/high 位的拆分是早期 C 语言的遗留问题,当时 64 位整数类型还不普遍(这就是为什么像 (U)LARGE_INTEGER
这样的结构甚至存在于 Win32 中的原因API).
所以:
Offset
OffsetHigh
64bit Value (Hex)
64bit Value (Decimal)
8
0
0x00000000'00000008
8
8
1
0x00000001'00000008
4'294'967'304
我正在查看一些使用 ReadFile
并指定 OVERLAPPED
类型的代码。
根据我目前阅读其他帖子的理解,这就是我得到的。
如果您想在文件的第 8 个字节开始一个 ReadFile
,您可以将 OVERLAPPED
的 Offset
变量设置为 8,并将 OffsetHigh
变量设置为在将 OVERLAPPED
传递给 ReadFile
之前为 0。这是有道理的。
现在,如果我们将 OffsetHigh
设置为 1 会怎样?
实际偏移量是一个64位整数。 Offset
字段为低32位,OffsetHigh
字段为高32位。 documentation:
Offset
The low-order portion of the file position at which to start the I/O request, as specified by the user.
...
OffsetHigh
The high-order portion of the file position at which to start the I/O request, as specified by the user.
...
The
Offset
andOffsetHigh
members together represent a 64-bit file position. It is a byte offset from the start of the file or file-like device, and it is specified by the user; the system will not modify these values. The calling process must set this member before passing theOVERLAPPED
structure to functions that use an offset, such as theReadFile
orWriteFile
(and related) functions.
这种 low/high 位的拆分是早期 C 语言的遗留问题,当时 64 位整数类型还不普遍(这就是为什么像 (U)LARGE_INTEGER
这样的结构甚至存在于 Win32 中的原因API).
所以:
Offset | OffsetHigh | 64bit Value (Hex) | 64bit Value (Decimal) |
---|---|---|---|
8 | 0 | 0x00000000'00000008 | 8 |
8 | 1 | 0x00000001'00000008 | 4'294'967'304 |