Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   mmap.3p    ( 3 )

карта страниц памяти (map pages of memory)

  Prolog  |  Name  |  Synopsis  |  Description  |  Return value  |  Error  |  Examples  |    Application usage    |  Rationale  |  Future directions  |  See also  |

Использование в приложениях (Application usage)

Use of mmap() may reduce the amount of memory available to other
       memory allocation functions.

Use of MAP_FIXED may result in unspecified behavior in further use of malloc() and shmat(). The use of MAP_FIXED is discouraged, as it may prevent an implementation from making the most effective use of resources. Most implementations require that off and addr are multiples of the page size as returned by sysconf().

The application must ensure correct synchronization when using mmap() in conjunction with any other file access method, such as read() and write(), standard input/output, and shmat().

The mmap() function allows access to resources via address space manipulations, instead of read()/write(). Once a file is mapped, all a process has to do to access it is use the data at the address to which the file was mapped. So, using pseudo-code to illustrate the way in which an existing program might be changed to use mmap(), the following:

fildes = open(...) lseek(fildes, some_offset) read(fildes, buf, len) /* Use data in buf. */

becomes:

fildes = open(...) address = mmap(0, len, PROT_READ, MAP_PRIVATE, fildes, some_offset) /* Use data at address. */