IPC inter-process communication + Shared Memory MappingIPC (Inter-Process Communication ).Mapping is a technology that maps the file content to the memory address. By ing the memory, it is generally easy to read and write files.Multiple processes map the same file ing object, that is, multiple processes map to the same physical storage page. Therefore, when a process writes data to the mapped memory, other processes can read data through the ing memory and implement inter-process communication through this mechanism.1. memory File ing Mapping File:
Process A creates A named ing object and writes the data to be shared in the ing memory. Process B opens the Mapping object through the object name, maps the Mapping object, and reads data from the ing memory.
2. Basic API functions:Create a Mapping object:HANDLE CreateFileMapping (
HANDLE hFile, // physical file HANDLE
LPSECURITY_ATTRIBUTES lpAttributes, // Security Settings
DWORD flProtect, // Protection Settings
DWORD dwMaximumSizeHigh, // large file size
DWORD dwMaximumSizeLow, // Low file size
Lptstr lpName // shared memory name
);This function returns the created ing object.Create ing memory:LPVOID MapViewOfFile (
HANDLE hFileMappingObject, // Mapping object
DWORD dwDesiredAccess, // access type
DWORD dwFileOffsetHigh, // ing file high
DWORD dwFileOffsetLow, // ing File status
SIZE_T dwNumberOfBytesToMap // Number of ing bytes
);
This function is used to create the ing memory of the Mapping object and return the ing memory.Memory replication:VOID CopyMemory (
PVOID Destination, // Destination address of the memory block to be copied
Const void * Source, // Source Address of the memory block to be copied
SIZE_T Length // Number of copied bytes
);This function is used to copy data to the ing memory.Open the Mapping object:HANDLE OpenFileMapping (
DWORD dwDesiredAccess, // access permission
BOOL bInheritHandle, // inheritance settings, generally set to FALSE
Lptstr lpName // Mapping Object Name
);This function is used to open an existing Mapping object. Return the Mapping object handle.3. Cow test:Run the process1 program in VC6.0 and the process2 program:
Running effect:
Process1 program:Process2 program: