Understanding and difference between inux memory ing and shared memory

Source: Internet
Author: User
We can see that an int FD (File Identifier) is required in the memory ing. The function maps the file content to a memory space through FD, I need to create another ing to get the file content and make statistics or modifications. In this case, I still use the MMAP function to create this ing. It still needs to use the FD file identifier, then I am not equal to re-opening the file to read the data in the file 1. in this case, what is the difference with direct file operations? 2. After ing to the memory, if the ing pointer ADDR is used to modify the content, will it modify the content in the shared memory or the file content? 3. To solve the above two problems, I still want to know exactly what the shared memory is ??? One answer |: 1. The execution speed of accessing shared memory is n times faster than that of directly accessing files (n, 10), which is very effective for scenarios requiring fast input and output. 2. The content modified through ADDR is the content in the shared content. Whether the file content has been modified depends on the file type. For files such as display devices, the file content is modified because it is directly written to the video memory. For common files, when the file is closed, the Kernel updates the data to the hard disk and other storage devices. 3. Shared Memory is mainly used to speed up program execution and facilitate the exchange of large data volumes among multiple processes. The second answer is: Memory ing of the modified file content: 1. You are not sure about this. For example, the memory ing of Display Device Files (video cards) does not allocate a new memory in the memory, but directly transmits the video address to the application through the ADDR parameter. In this way, when an application modifies a file through memory ing, it directly modifies the content in the video memory (that is, changes the display content ). 2. I feel that you have mixed the memory ing with the shared memory. Memory ing is used to accelerate access to files/devices. (If it is a large file and you want to increase the read/write speed, we recommend that you use memory ing .) Shared Memory is used to quickly exchange large data volumes among multiple processes. 3. FD is the file descriptor. It has no direct relationship with memory ing. Only after the memory ing is done can it correspond to the mapped memory. For memory ing that does not modify the file content, you can specify the memory to which the file content is mapped in the program. For multiple processes to open the same file, different memory ing can open up multiple memory areas. The file content is updated in the order of the process that closes the file. Therefore, there is a dirty read problem. 2, :-), be sure to remember that the memory ing is used to speed up access to files/devices, not for data communication. Reposted from: Success! Shared Memory, as its name implies, is the reserved memory area, which allows a group of processes to access it. Shared memory is the fastest and simplest communication mechanism in system vipc. After a process obtains the shared memory, it uses the same memory as other memories. Operations performed by a process on the shared memory are immediately visible to other processes, because each process only needs a pointer to the shared memory space to read the content in the shared memory (to put it bluntly, it is like applying for a piece of memory, every required process has a pointer pointing to the memory.) The results can be easily obtained. Attention should be paid to when using shared memory: shared memory cannot ensure mutual exclusion of memory operations. A process can write data to a given address in the shared memory, while another process reads data from the same address, which may lead to inconsistent data. Therefore, processes that use shared memory must ensure that read and write operations are strictly mutually exclusive. Locks and atomic operations can be used to solve this problem. You can also use semaphores to ensure mutual access to the shared memory area. In some cases, the Message Queue can be replaced in the shared memory, and the read/write ratio of the shared memory is faster than that of the message queue!

 

Understanding and difference between inux memory ing and 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.