File Memory ing MMAP

Source: Internet
Author: User
MMAP can map a part of the disk file directly to the memory, so that the location in the file has a corresponding memory address, you can directly use pointers to read and write files without the need for the read/write function.
Prototype: # include
Void * MMAP (void * ADDR, size_t Len, int Prot, int flag, int filedes, off_t off );
Int munmap (void * ADDR, size_t Len );

The parameters are explained as follows: the overall length is equivalent to the size of the disk file to be moved to the memory. If the ADDR parameter is null, the kernel selects an appropriate address in the process address space to create a ing. If ADDR is not null, a prompt is sent to the kernel indicating the address to start ing. The kernel will select a suitable address on the ADDR to start ing. After the ing is established, the real ing first address can be obtained through the return value. The LEN parameter is the length of the part of the file to be mapped. The off parameter is mapped from where the file is located and must be an integer multiple of the page size (usually 4 K in 32-bit system structure ). Filedes indicates the descriptor of the open file.
The prot parameter has four values:
Prot_exec indicates that this segment of ing can be executed, for example, ing a shared library
Prot_read indicates the readable part of the ing.
Prot_write indicates the writable section of the ing.
Prot_none indicates that this segment of the ing is not accessible.
There are many flag parameters. Here we only talk about two types,
Map_shared multiple processes share the ing of the same file. One process modifies the mapped memory, and the other process also sees this change.
Map_private multiple processes do not share the ing of the same file. One process modifies the mapped memory, and the other process does not see this change or write it into the file.

The most important thing to understand is that before the ing, you need to read or write the function.CompositionAfter the ing, you use the pointer to operate the file.

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.