mmap function for Shared memory

Source: Internet
Author: User

Mmap maps a file or other object into memory. Mmap can also implement shared memory. mmap function calls enable shared memory between processes by mapping the same file. After the file is mapped to the process address space, the process can manipulate the file like read-write memory.

Function prototype: void* mmap(void* addr,size_t length,int prot,int flags,int fd,off_t offset);


Addr: The start address of the map area, set to 0, indicates the system determines the starting address of the map area

Length: The size of the map area. length units are bytes

Prot: The desired memory protection flag. Take the following values:

Port_exec: page content can be executed Port_read: page content can be read

Port_write: page content can be written to Prot_none: page content is inaccessible

Flag: Specifies the type of the mapped object, and whether the mapping options are shared with the mapped page.

map_shared: shares the mapping space with all other processes that map this object.

              map_fixed:

              FD: Valid file descriptor. Returns, by the general open () function, whose value can be set to-1. You need to specify the flags parameter to                       &NBSP ; Map_anon, indicating that the anonymous mapping is in progress.

Offset: The starting point for the content of the mapped object.

Return value: Succeeded, returns a pointer to the mapped area; failed, returns-1.

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/85/80/wKiom1el5IORFskaAAB9GIoxJaM705.png "style=" float: none; "title=" 1.PNG "alt=" Wkiom1el5iorfskaaab9gioxjam705.png "/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/85/80/wKioL1el5ITRtUhdAAAUW3Pui8w870.png "style=" float: none; "title=" 3.PNG "alt=" Wkiol1el5itrtuhdaaauw3pui8w870.png "/>




This article from "Together to see the Stars" blog, reproduced please contact the author!

mmap function for Shared memory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.