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.
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.-Rajat
On Fri, Jan 11, 2013 at 2:44 AM, horseriver <horserivers@xxxxxxxxx> wrote:
hi:
these two wayes of operating one file :
1.use open/write interface call .
2.mmap this file into memory , then access this memory area and do r/w .
what is the essential difference between this teo wayes?
thanks!
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies