Memory Mapped Files
Posted on 2003-12-08
I've got a file consisting of 32 byte structs that changes frequently and requires random access. Sounds like a good case for a Memory Mapped file.
It's been a while since I've worked with memory mapped files but I seem to recall that the OS loads the file into memory one "page" at a time, a page being a slice of the file probably only about 4kb in size. If you modify any values in this "page" then I beleive the OS considers it dirty and writes it back to the file. When does it do this? When it unloads the page? When you unmap the file? Can you share a memory mapped file between threads? Is it safe for thread A and thread B to read and write from the same memory map at the same time? Will thead B see any changes that thread A makes to it? Or will you need to provide some sort of synchronization for the threads?
Just full of questions this morning.