I need to have two processes share information through a memory mapped file. One of them is going to only read to the file and the other is only going to write to it.
Is it OK for me just to leave the file always mapped to those two processes? I am currently:
- mapping the file to the reader process
- Writing
- Unmapping the file
- Mapping the file to the writer process
- reading
- Unmapping
And repeating over and over every time I need the processes to share information. My concern is that all these calls to map and unmap may be expensive. Should I keep the file mapped to both process al the time? I could regulate the access to the shared memory through mutexes.
What is the best way to do this kind of task?
You don’t need to unmap the file after reading or writing at all. Windows guarantees that the data “visible” in the mapping in two processes will be the same when the local file is mapped on one computer.