Please note that the content of this book primarily consists of articles
available from Wikipedia or other free sources online. A memory-mapped
file is a segment of virtual memory which has been assigned a direct
byte-for-byte correlation with some portion of a file or file-like
resource. This resource is typically a file that is physically present
on-disk, but can also be a device, shared memory object, or other
resource that the operating system can reference through a file
descriptor. Once present, this correlation between the file and the
memory space permits applications to treat the mapped portion as if it
were primary memory. The primary benefit of memory mapping a file is
increasing I/O performance, especially when used on small files.
Accessing memory mapped files is faster than using direct read and write
operations for two reasons. Firstly, a system call is orders of
magnitude slower than a simple change to a program's local memory.
Secondly, in most operating systems the memory region mapped actually is
the kernel's page cache, meaning that no copies need to be created in
user space.