gpt4 book ai didi

c# - MemoryMappedFile.CreateNew(...) 是否保证创建一个带零的文件?

转载 作者:太空狗 更新时间:2023-10-29 23:44:51 31 4
gpt4 key购买 nike

正如标题所说;我可以依赖 MemoryMappedFile 来创建一个全为零的文件吗?我已经通过读取一些新创建的文件进行了测试,但这种“测试”似乎是徒劳的,尽管我还没有看到非零字节。

是否有任何我遗漏的相关文档,或者只是假设内存映射文件在创建时为空。

最佳答案

不,这不能保证。这似乎是特定于实现的。

虽然在 MemoryMappedFile 中没有提到,它在 .NET 中使用的底层原生 API 的行为 (CreateFileMapping) 确实明确记录了这一点,并且它有所不同,具体取决于存储的来源。

在文件支持映射的情况下:

If the file is extended, the contents of the file between the old end of the file and the new end of the file are not guaranteed to be zero; the behavior is defined by the file system.

在匿名映射的情况下(由页面文件支持):

The initial contents of the pages in a file mapping object backed by the operating system paging file are 0 (zero).

关于c# - MemoryMappedFile.CreateNew(...) 是否保证创建一个带零的文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30714650/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com