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