我担心通过CreateFileMapping在 FAT 文件系统上使用内存映射 IO 的危险。具体情况是用户直接从 U 盘打开文档(是的,您尝试禁止他们这样做!)。
MSDN管理内存映射文件一文没有说明文件系统约束。
更新
我没有任何真正的理由担心,但有一种模糊的感觉,我在某个时候读到过关于他们的问题(我的职业生涯跨越了 25 年,所以我的记忆中有很多模糊的深度,一路回溯到8位微!)。是否应该支持他们的问题对我来说非常重要,所以我想问是否有人可以证实我的担忧。谢谢你让我放心。
我担心通过CreateFileMapping在 FAT 文件系统上使用内存映射 IO 的危险。具体情况是用户直接从 U 盘打开文档(是的,您尝试禁止他们这样做!)。
MSDN管理内存映射文件一文没有说明文件系统约束。
更新
我没有任何真正的理由担心,但有一种模糊的感觉,我在某个时候读到过关于他们的问题(我的职业生涯跨越了 25 年,所以我的记忆中有很多模糊的深度,一路回溯到8位微!)。是否应该支持他们的问题对我来说非常重要,所以我想问是否有人可以证实我的担忧。谢谢你让我放心。
Memory-mapped files is one of my favorite features. It's absolutely no danger. It's one of the base extremely optimized Windows I/O features. If one starts an EXE or load indirect a DLL it is implemented internally as memory-mapped file mapping.
It is supported on all types of file systems including FAT.
By the way atzz say that memory-mapped files are allowed on network drives. I can add it is not only allowed, but it is strictly recommended to use memory-mapped file also with files from network. In the case the I/O operation will be cached in very good way, which is not done with other (C/C++) I/O.
If you want that the EXE will not crash if you open it from the CD or network one can mark Program Executable with one bit in the header (linker switch /SWAPRUN see http://msdn.microsoft.com/en-us/library/chzz5ts6.aspx). There are no option for documents opened from USB stick.
But what exact problem do the users have? Do they don't use "Safely Remove Hardware" Icon? Then they have to learn to do this exactly like they have to learn to not switch computer power, but shutdown the computer properly.
Could you explain why you find dangers to use memory-mapped files, and in what situations you have problems and is usage of other I/O operation has no such problem?
是的,它确实。它甚至支持 CDFS 或网络驱动器上的文件映射。你怀疑的根源是什么?