Key points of unix shared memory

Source: Internet
Author: User
Unix shared memory highlights shared memory advantages: 1. fast and efficient data transmission between processes without passing data through the kernel, that is, copying data without calling the system. 2. as the kernel continues * nix shared memory has two sets of APIs: Posix and SystemV. The main difference is the size of the shared memory...
Unix shared memory highlights shared memory advantages: 1. fast and efficient data transmission between processes without passing data through the kernel, that is, copying data without calling the system. 2. as the kernel continues * nix shared memory has two sets of APIs: Posix and System V. The main difference between the two is the size of the shared memory.
1. Posix Shared memory size can be modified at any time through the ftruncate function. 2. the size of System V shared memory has been determined at the time of creation, and the maximum value varies according to the System's Posix Shared Memory # include (Mmap, munmap, msync, shm_open, shm_unlink) main function -- mmap void * mmap (void * addr, size_t len, int prot, int flags, int fd, off_t offset) the function maps a handle to the memory. the handle can be an open file handle or a shm_open shared memory area object. * In view of all files in nix, shm_open creates a file object in the/dev/shm directory and returns the object descriptor. Www.2cto.com mmap maps the handle as the underlying supporting object of the shared memory to the memory, so that the memory can be shared between processes without reading or writing. It is estimated that the more primitive way to transmit data between * nix processes is to read and write a file between processes. However, frequent open, read, write, and lseek system calls consume too much computing resources. So I thought of ing the file handle to the memory, which improves the efficiency of data transmission between processes. Note: When msync modifies the memory in the memory ing area, the kernel updates the file content at a certain time point. To ensure that the file is updated, call the msync function. File updates can be synchronous (MS_SYNC) or asynchronous (MS_ASYNC ). (The function write update file is also called here.) System V shared memory # include (Shmget, shmat, shmdt, shmctl) because System V's shared memory has a size limit, you can consider using a shared memory array to solve this problem. Although the size of the array is also limited by the amount of shared memory that a process can obtain, it can alleviate the problem that a single shared memory of System V is too small. Author Range
Related Article

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.