[IPC process Communication 3] memory ing File

Source: Internet
Author: User

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:


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.