SetFileValidData在做什么? SetEndOfFile有什么区别? [英] What does SetFileValidData doing ? what is the difference with SetEndOfFile?

查看:352
本文介绍了SetFileValidData在做什么? SetEndOfFile有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种异步高效地扩展文件的方法.

I look for a way to extend a file asynchronously and efficiently .

在支持文档中,异步磁盘I/O显示为同步在Windows NT,Windows 2000和Windows XP上说:

注意:应用程序可以进行前面提到的写操作 通过使用以下命令更改文件的有效数据长度来实现异步 SetFileValidData函数,然后发出WriteFile.

NOTE: Applications can make the previously mentioned write operation asynchronous by changing the Valid Data Length of the file by using the SetFileValidData function, and then issuing a WriteFile.

在MSDN中,SetFileValidDataSets the valid data length of the specified file的功能.

in MSDN, SetFileValidData is a function for Sets the valid data length of the specified file.

但是我仍然不知道什么是有效数据",它与文件大小有什么区别?

But I still not understand what is the "valid data", what is the difference between it and the size of file?

我可以使用SetFilePointerExSetEndOfFile扩展文件大小,但是如何通过SetFileValidData扩展文件大小?

I can use SetFilePointerEx and SetEndOfFile to extend the file size, but how do this by SetFileValidData?

SetFileValidData无法输入大于文件大小的参数.在这种情况下,SetFileValidData的真实含义是什么?

SetFileValidData cannot input a argument large than the size of file. In this case, what is the living meaning of SetFileValidData?

推荐答案

使用SetEndOfFile来增加文件的长度时,逻辑文件的长度会更改,并且会分配必要的磁盘空间,但实际上并没有物理上的数据写入与文件新部分相对应的磁盘扇区.有效数据长度保持不变.

When you use SetEndOfFile to increase the length of a file, the logical file length changes and the necessary disk space is allocated, but no data is actually physically written to the disk sectors corresponding to the new part of the file. The valid data length remains the same as it was.

这意味着您可以使用SetEndOfFile来非常快地使文件变得非常大,如果您从文件的新部分读取内容,则只会得到零.当您将实际数据写入文件的新部分时,有效数据长度会增加.

This means you can use SetEndOfFile to make a file very large very quickly, and if you read from the new part of the file you'll just get zeros. The valid data length increases when you write actual data to the new part of the file.

如果您只想保留空间,然后将数据顺序写入文件中就可以了.但是,如果使文件很大,并立即在文件末尾写入数据,则需要将零写入文件的新部分,这将花费很长时间.如果您实际上不需要文件包含零,则可以使用SetFileValidData跳过此步骤;否则,请使用SetFileValidData跳过此步骤.文件的新部分将包含以前删除的文件中的随机数据.

That's fine if you just want to reserve space, and will then be writing data to the file sequentially. But if you make the file very large and immediately write data near the end of it, zeros need to be written to the new part of the file, which will take a long time. If you don't actually need the file to contain zeros, you can use SetFileValidData to skip this step; the new part of the file will then contain random data from previously deleted files.

附录:

  • 稀疏文件的规则不同.

  • The rules for sparse files are different.

您应该在非特权用户具有读取权限的文件上使用SetFileValidData;这可能会从属于其他用户的已删除文件中泄漏内容.

You should not use SetFileValidData on a file that non-privileged users have read access to; this could leak content from deleted files that belonged to other users.

这篇关于SetFileValidData在做什么? SetEndOfFile有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆