在Windows上创建大文件

我需要创建一个较大的(1-8 GB)大文件。在Windows上使用C或C最快的方​​法是什么?我需要快速创建它们,速度真的是一个问题。文件将用于存储仿真,即将以不同的偏移量随机访问,我需要所有存储将被预分配但未初始化,目前我们正在使用伪数据写入所有存储,并且耗时太长。

谢谢。

使用Win32 API, CreateFileSetFilePointerExSetEndOfFileCloseHandle.按同样的顺序。

这个技巧在SetFilePointerEx函数中。从MSDN:

Note that it is not an error to set
the file pointer to a position beyond
the end of the file. The size of the
file does not increase until you call
the SetEndOfFile,WriteFile,or
WriteFileEx function.

Windows资源管理器在将文件从一个位置复制到另一个位置时,实际上也是这样做的。它执行此操作,以便磁盘不需要为碎片磁盘重新分配文件。

相关文章

文章浏览阅读2.2k次,点赞6次,收藏20次。在我们平时办公工作...
文章浏览阅读1k次。解决 Windows make command not found 和...
文章浏览阅读3.2k次,点赞2次,收藏6次。2、鼠标依次点击“计...
文章浏览阅读1.3w次。蓝光版属于高清版的一种。BD英文全名是...
文章浏览阅读974次,点赞7次,收藏8次。提供了更强大的功能,...
文章浏览阅读1.4w次,点赞5次,收藏22次。如果使用iterator的...