Question

How correctly open/use file mapping on Windows with ability to write to it from another process without file mapping;

For example process A writes big log file, it open file, write new data to the end, or rewrite it with new data.

Process B in parallel open this file as file mapping and from time to time read memory pages for updates without closing file mapping.

Please don't ask why I wanna to do logic I explained above. I need to know could it be done?

Was it helpful?

Solution

There's nothing stopping you from having a file mapping object associated with a file that you're updating with normal file system functions (ReadFile, WriteFile, etc.). But you won't like the results. Windows guarantees that the file mapping view will be coherent if other processes update the file through the file mapping functions. It makes no such guarantees when the file is updated some other way. In fact, it pretty much guarantees that what the file mapping view shows will not match the actual contents of the file.

So, yes, you can do this. But you shouldn't, because there's no way you can guarantee that what the mapped view sees is what's actually in the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top