gpt4 book ai didi

c++ - mmap() : what happens if underlying file changes (shrinks)?

转载 作者:IT王子 更新时间:2023-10-29 00:33:31 25 4
gpt4 key购买 nike

如果您使用 mmap() 对文件进行内存映射,但随后底层文件的大小变小了很多。如果您访问从文件中删除的内存偏移量,会发生什么情况?

最佳答案

IBM 说它是未定义的 http://publib.boulder.ibm.com/infocenter/iseries/v5r3/index.jsp?topic=%2Fapis%2Fmmap.htm

If the size of the mapped file is decreased after mmap(), attempts to reference beyond the end of the file are undefined and may result in an MCH0601 exception.

If the size of the file increases after the mmap() function completes, then the whole pages beyond the original end of file will not be accessible via the mapping.

在 SingleUnixSpecification: http://pubs.opengroup.org/onlinepubs/7908799/xsh/mmap.html 中也是这样说的

If the size of the mapped file changes after the call to mmap() as a result of some other operation on the mapped file, the effect of references to portions of the mapped region that correspond to added or removed portions of the file is unspecified.

“未定义”或“未指定”表示 - 允许操作系统开始格式化磁盘或任何东西。最有可能是 SIGSEGV 杀死了您的应用程序。

关于c++ - mmap() : what happens if underlying file changes (shrinks)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6875771/

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