重叠/异步 I/O 如何工作
假设我有类似的东西
readFile(.....&ol) //with overlapped
while(1){
////////.....
waitforsingleobject(//ol.hevent);
////
readfile(.....&ol)
}
,我注意到两个读取文件都从文件的开头读取......为什么?在没有重叠/异步的正常读取文件中,第二个读取文件将从第一个读取文件结束的位置开始。
Supposed I have something like this
readFile(.....&ol) //with overlapped
while(1){
////////.....
waitforsingleobject(//ol.hevent);
////
readfile(.....&ol)
}
I noticed that both readfiles read from the beginning of the file...why? In a normal readfile without overlapped/asynchronization the second readfile would start off where the first ended..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在文件上使用重叠 I/O 时,您将传递一个指向
OVERLAPPED
对象的指针,在本例中为ol
。OVERLAPPED
结构体有两个变量:Offset
和OffsetHigh
。这两个变量组合成一个64位整数,Offset
为低位DWORD,OffsetHigh
为高位DWORD,作为执行的偏移量的 I/O 操作。因此,例如,如果您想在文件的第 8 个字节处启动
ReadFile
,则可以将Offset
变量设置为 8,并将OffsetHigh
设置为 8。在将OVERLAPPED
传递给ReadFile
之前,将 code> 变量设置为 0。When using overlapped I/O on a file, you pass a pointer to an
OVERLAPPED
object, in this caseol
.The
OVERLAPPED
struct has two variables,Offset
andOffsetHigh
. These two variables are combined into a 64-bit integer, withOffset
being the lower-order DWORD andOffsetHigh
being the high-order DWORD, and used as the offset to perform the I/O operation at.So, for example, if you wanted to start a
ReadFile
at the 8th byte of the file, you would set theOffset
variable to 8 and theOffsetHigh
variable to 0 before passing theOVERLAPPED
toReadFile
.