Search code examples
c++terminologymmapmemory-mapped-files

What are memory mapped files?


Recently, I've come across this video that shows how to use mmap() with file io. However, I can't find the video of his that documents the function. I don't have an understanding of what it is, why it exists, nor how it relates to files.

Too much of the jargon is flying over my head to make sense of it. I had the same problem with sites like Wikipedia.


Solution

  • Files are arrays of bytes stored in a filesystem.

    "Memory" in this case is an array of bytes stored in RAM.

    Memory mapping is something that an operating system does. It means that some range of bytes in memory has some special meaning.

    Memory mapped file is generally a file in the file system, which has been mapped by the operating system to some range of bytes in memory of a process. When the process writes to the memory of the process, the operating system takes care that the bytes are written to the file, and when the process reads from the memory, operating system takes care that the file is read.