<div dir="ltr"><div><div>Default read/write inerfaces are better suited for sequential read/write within your program. Although you can seek to any location within the file, you still have overhead to issue system calls to get data. However mmap allows you to map a section of file into program address space. Now if your access patter is rather random, modifying few bytes here and there, but at random offset. You just get continous memory array, which is much easier than issuing read and write at different file offsets.<br>
<br></div>A most common and mandatory use case of mmap is in mapping executable binary program image, and libraries into process address spaces. Access pattern for a program is not sequential, you can have multiple jump (if, else, for loop), so it is better suited with mmap. It is read only and private memory mapping, Any modifications you do will create a COW page which if private to your process, so that is another advantage of mmap which is completely transparent to user mode. If your filesystem does not support, this basic mmap mode, you can not execute a binary file stored in this filesystem, unless you copy it to some other filesystem which does.<br>
<br></div>Apart from this, read more about mmap from UTLK book.<br><br>-Rajat<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 11, 2013 at 2:44 AM, horseriver <span dir="ltr"><<a href="mailto:horserivers@gmail.com" target="_blank">horserivers@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">hi:<br>
<br>
these two wayes of operating one file :<br>
<br>
1.use open/write interface call .<br>
<br>
2.mmap this file into memory , then access this memory area and do r/w .<br>
<br>
what is the essential difference between this teo wayes?<br>
<br>
thanks!<br>
</blockquote></div><br></div>