How can I limit file fragmentation while working w

2020-02-12 10:39发布

In my application I am gathering small data bits into a bigger file over time. As a result, the target file becomes excessively fragmented. What can be done to limit fragmentation of the output file with .NET?

2条回答
女痞
2楼-- · 2020-02-12 11:04

The only way you can reliably reduce file fragmentation is to allocate space for the complete file in one go (fill the rest of the file with zeros, as filler). But this can only be done if you have some idea of the final size of the file.

Another option would be to increase the file size by a certain value during each increment (say, 100 MB). That way you would have lesser defragmented chunks.

查看更多
Juvenile、少年°
3楼-- · 2020-02-12 11:18

You could deliberately increment the file size in larger chunks and internally monitor where the end of your current usage is. That way you give the system a better chance of allocating contiguous space for your file.

查看更多
登录 后发表回答