Memory Mapped Files
Depends on | File Access • Memory |
---|
A method of file access, memory mapping a file (or device) is a way of making the file appear in a process’ virtual address space. This is not necessarily as comprehensive as the more traditional file access methods – note that all the opened files need to fit in the process’ space and, sometimes, files are large (though with the advent of 64-bit address spaces on larger machines this will probably be less of a problem … at least for a few years). On the other hand it can be convenient to use and will typically be significantly faster than making sets of system calls.
Memory mapping a file on a virtual memory system does not mean the whole file is read into RAM! Usually a “lazy” approach will be used where only the appropriate pages will be fetched, on demand. This is basically the same demand paging mechanism used in virtual memory.
There is a worked example of this process in the download mmap
. This contains quite a few obscure calls; the important point is the text from the file appears in an ordinary array.
Also refer to: | Operating System Concepts, 10th Edition: Chapter 13.5, pages 555-560 |
---|