tags:

views:

45

answers:

2

I'm concerned about the dangers of using memory-mapped IO, via CreateFileMapping, on FAT filesystems. The specific scenario is users opening documents directly from USB sticks (yeah, you try and ban them doing this!).

The MSDN Managing Memory-Mapped Files article doesn't say anything about file system constraints.

Update

I didn't have any real reason to be concerned but a vague feeling that I'd read about problems with them at some point (my career spans over 25 years so I have a lot of vague depths in my memory, all the way back to 8-bit micros!). The issue of whether or not they should be supported is pretty important for me to recommend so I wanted to ask if anyone could corroborate my concerns. Thanks for putting my mind at rest.

+3  A: 

Yes it does. It even supports mapping of files on CDFS or on network drives. What is the source of your doubts?

atzz
+2  A: 

Memory-mapped files is one of my favorite features. It's absolutely not danger. It's one of the based extremely optimizes 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 inclusive 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 EXE will be 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 exactly problem have users? Do they don't use "Safely Remove Hardware" Icon? Then they have to study to do this exactly that they have to study don't switch computer power, but shutdown the computer.

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?

Oleg