How can I limit file fragmentation while working with .NET?

房东的猫 提交于 2019-12-29 07:57:09

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/917309/how-can-i-limit-file-fragmentation-while-working-with-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!