"IPC interprocess communication Three" memory-mapped files mapping file

Source: Internet
Author: User

IPC Inter-process communication+ Shared Memory mapping       IPC(inter-process communication, interprocess communication). file Mapping (Mapping) is a technique for mapping the contents of a file to a memory address , and reading and writing a file is as simple as reading and writing memory by mapping memory. Multiple processes map the same file-mapping object , that is, multiple processes are mapped to the same physical storage page, so when a process writes data to the mapped memory, Other processes can read data through mapped memory, and this mechanism enables interprocess communication.           1. The memory file mapping mapping file :
a process creates a named mapping object and writes the data that needs to be shared in the mapped memory. the b process opens the mapping object through the object name, maps the mapping object, and reads the data from the mapped memory.
2. Basic API Functions : founding mapping objects: HANDLEcreatefilemapping(
HANDLE hfile,//physical file handle
lpsecurity_attributes Lpattributes,Security settings
DWORD Flprotect,//Protection settings
DWORD Dwmaximumsizehigh,//High file size
DWORD Dwmaximumsizelow,//Low file size
LPCTSTR lpname//Shared memory name
);
The function returns the created mapping object. To create a mapped memory: lpvoidMapViewOfFile(
HANDLE Hfilemappingobject,//mapping Object
                         DWORD dwDesiredAccess,//Access Categories
                        DWORD Dwfileoffsethigh,//Map file High
                         DWORD Dwfileoffsetlow,//Map file status
                         size_t Dwnumberofbytestomap//Number of mapped bytes
);
This function is used to create the mapped memory of the mapping object and return the mapped memory. Memory Replication : VOIDCopyMemory(
                   PVOID Destination,           //The destination address of the memory block to be copied
                   CONST VOID *source,//To copy the source address of the memory block
                   size_t Length//Number of bytes copied
);
This function is used to copy data to mapped memory. Open the Mapping object: HANDLEopenfilemapping(
                         DWORD dwDesiredAccess,//access rights
                         BOOL bInheritHandle,//Inheritance settings, generally set to false
                         LPCTSTR lpname//Mapping object name
);
This function is used to open an existing mapping object. Returns a handle to the mapping object.    3. kind: Run the process1 program in VC6.0 first, run the PROCESS2 program:
operating effect :
Process1 Program: Process2 Program:


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.