Memory-mapped I/O functions

1.void  * mmap((void *addr, size_t length, int prot, int flags, int fd, off_t offset)

 parameter:

    addr: used to specify the starting address of the mapped memory area, usually set to 0, indicating that the system selects the mapped address by itself, and the function returns the starting address of the mapped area

    length: length of the mapping area (number of bytes)

    prot: PROT_READ mapped area is readable

       PORT_WRITE writable

    flags: MAP_SHARED mapping is successful, if the memory is changed, the disk will also change

       MAP_PRIVATE mapping is successful, only the memory is changed, the disk will not change

    fd: the file to operate on

    offset: offset to where to start mapping in the file

2.int munmap(void *addr,size_t len) //Unmap

3. Notes:

  3.1 The mapping length cannot be greater than the file length, otherwise a segmentation fault will occur. If you want to lengthen the mapping space, you can call the function

    ftruncate(fd,size);

  3.2 IO for mmap mapping, even if only write mapping, the file to be mapped must be opened in RDWR mode

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324981712&siteId=291194637