I understand the use of mmap. Consideration of a simple read / write operation in a file includes opening a file and allocating a buffer, reading [which requires a context switch], and then the data available to the user in the buffer, and changes to the buffer do not reflect into the file if it is not written explicitly.
Instead, if we use mmap, direct access to the buffer is nothing more than an attachment to a file.
Question:
1) The file is located on the hard disk, mmaped in the process. Every time I write to mmaped memory, is it written directly to the file? . In this case, it does not require any context switching , because changes are made directly in the file itself. If mmap is faster than accessing an obsolete file, where do we see time savings?
Please explain. correct me if I am wrong.
source share