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

Source: Internet
Author: User
<span id="Label3"></p><span style="font-size:32px; color:rgb(153,0,0)"><span style="font-size:32px; color:rgb(153,0,0)">IPC inter-process Communication</span></span><span style="font-size:32px"><span style="font-size:32px">+ Shared Memory mapping</span></span><span style="font-size:32px"><span style="font-size:32px">      </span></span><span style="font-size:32px"><span style="font-size:32px"><span style="font-size:18px"><strong> <span style="color:rgb(204,102,0)">IPC</span>(inter-process Communication. Interprocess communication). </strong></span></span></span><span style="font-size:32px"><span style="font-size:18px"><strong><strong> <span style="color:#333333">file Mapping (Mapping) is a</span> technique for mapping the contents of a <span style="color:#cc6600">file</span> <span style="color:#333333">to</span> a <span style="color:#cc6600">memory address</span> , and <span style="color:#333333">reading and writing a file is as simple as reading and writing memory by mapping Memory.</span></strong><p><strong></strong></p></strong><p><p><strong></strong><span style="font-size:32px"><span style="font-size:18px"><strong><span style="color:#333333"></span> <span style="color:#33cc00">Multiple processes</span> <span style="color:#333333">map</span> The <span style="color:#33cc00">same file mapping object</span> , that is, <span style="color:#333333">multiple processes are mapped to the same physical storage page, So. When a process writes data to mapped memory, other processes can read the data through mapped memory. This mechanism enables inter-process Communication. </span></strong></span></span></p></p><p><span style="font-size:32px"><span style="font-size:32px"><span style="font-size:18px"><strong><span style="color:#333333">         </span></strong></span></span></span><span style="font-size:32px"><span style="font-size:32px"><span style="font-size:18px"><strong>1. The <span style="color:#cc6600">memory file mapping mapping </span>file <span style="color:#333333">:</span> <span style="color:#333333"> </span></strong></span></span></span><span style="font-size:32px"><span style="font-size:32px"><span style="font-size:18px"><strong><span style="color:#333333"><br></span></strong></span></span></span><span style="font-size:32px"><span style="font-size:32px"><span style="font-size:18px"><strong>a process <span style="color:#33cc00"></span> creates a named mapping object and writes the data that needs to be shared in the mapped memory. <span style="color:#333333"> </span> <span style="color:#333333"> </span>the <span style="color:#33cc00">b process</span> <span style="color:#333333">opens the mapping object through the object name and maps the mapping Object. Reads data from the mapped memory. </span></strong></span></span></span><span style="font-size:32px"><span style="font-size:32px"><span style="font-size:18px"><strong><span style="color:#333333"><br></span></strong></span></span></span><span style="font-size:32px"><span style="font-size:32px"><span style="font-size:18px"><strong>2. <span style="color:#cc6600">Basic API Functions</span> <span style="color:#333333">:</span> <span style="color:#333333"> </span></strong></span></span></span><strong><strong><span style="color:#cc6600"> <span style="font-size:18px">founding</span> <span style="font-size:18px">mapping objects:</span> </span></strong></strong><strong><span style="font-size:18px; color:#333333"><span style="font-size:18px; color:#333333">HANDLE</span></span><span style="font-size:18px; color:#33cc00"><span style="font-size:18px; color:#33cc00">createfilemapping</span></span><span style="font-size:18px; color:#333333"><span style="font-size:18px; color:#333333">(<br></span></span><span style="font-size:18px; color:#993399"><span style="font-size:18px; color:#993399">HANDLE hfile,</span></span><span style="font-size:18px; color:#333333"><span style="font-size:18px; color:#333333">//physical File Handle<br></span></span><span style="font-size:18px; color:#993399"><span style="font-size:18px; color:#993399">lpsecurity_attributes lpattributes,</span></span><span style="font-size:18px; color:#333333"><span style="font-size:18px; color:#333333">Security settings<br></span></span><span style="font-size:18px; color:#993399"><span style="font-size:18px; color:#993399">DWORD flprotect,</span></span><span style="font-size:18px; color:#333333"><span style="font-size:18px; color:#333333">//protection Settings<br></span></span><span style="font-size:18px; color:#993399"><span style="font-size:18px; color:#993399">DWORD dwmaximumsizehigh,</span></span><span style="font-size:18px; color:#333333"><span style="font-size:18px; color:#333333">//high File Size<br></span></span><span style="font-size:18px; color:#993399"><span style="font-size:18px; color:#993399">DWORD dwmaximumsizelow,</span></span><span style="font-size:18px; color:#333333"><span style="font-size:18px; color:#333333">//low File Size<br></span></span><span style="font-size:18px; color:#993399"><span style="font-size:18px; color:#993399">LPCTSTR lpname</span></span><span style="font-size:18px; color:#333333"><span style="font-size:18px; color:#333333">//shared Memory Name<br>);</span></span></strong><strong><strong><span style="font-size:18px; color:#333333">The function returns the created mapping Object. </span></strong></strong></p><p><span style="font-size:18px; color:#cc6600">to <span style="font-size:18px; color:#cc6600"><strong>Create a mapped memory:</strong></span></span><span style="font-size:18px"><strong><span style="color:#333333"><span style="color:#333333">lpvoid</span></span><span style="color:#33cc00"><span style="color:#33cc00">MapViewOfFile</span></span><span style="color:#333333"><span style="color:#333333">(</span></span><br><span style="color:#333333"><span style="color:#333333"></span></span><span style="color:#993399"><span style="color:#993399">HANDLE hfilemappingobject,</span></span><span style="color:#333333"><span style="color:#333333">//mapping Object</span></span><br><span style="color:#333333"><span style="color:#333333">                         </span></span><span style="color:#993399"><span style="color:#993399">DWORD dwdesiredaccess,</span></span><span style="color:#333333"><span style="color:#333333">//access Categories</span></span><br><span style="color:#333333"><span style="color:#333333">                        </span></span><span style="color:#993399"><span style="color:#993399">DWORD dwfileoffsethigh,</span></span><span style="color:#333333"><span style="color:#333333">//map File High</span></span><br><span style="color:#333333"><span style="color:#333333">                         </span></span><span style="color:#993399"><span style="color:#993399">DWORD dwfileoffsetlow,</span></span><span style="color:#333333"><span style="color:#333333">//map file Status</span></span><br><span style="color:#333333"><span style="color:#333333">                         </span></span><span style="color:#993399"><span style="color:#993399">size_t Dwnumberofbytestomap</span></span><span style="color:#333333"><span style="color:#333333">//number of mapped bytes</span></span><br><span style="color:#333333"><span style="color:#333333">);</span></span><br></strong></span><span style="font-size:18px"><span style="font-size:18px"><strong><span style="color:#333333">This function is used to create the mapped memory of the mapping object and return the mapped memory. </span></strong></span></span></p><p><span style="font-size:18px"><span style="font-size:18px"><strong> <span style="color:#cc6600">Memory Replication</span> <span style="color:#cc9933">:</span> </strong></span></span><span style="font-size:18px"><strong><span style="color:#333333"><span style="color:#333333">VOID</span></span><span style="color:#33cc00"><span style="color:#33cc00">CopyMemory</span></span><span style="color:#333333"><span style="color:#333333">(</span></span><br><span style="color:#333333"><span style="color:#333333">                   </span></span><span style="color:#993399"><span style="color:#993399">PVOID Destination,</span></span><span style="color:#333333"><span style="color:#333333">           </span></span><span style="color:rgb(51,51,51)"><span style="color:rgb(51,51,51)">//the Destination Address of the memory block to be copied</span></span><br><span style="color:#333333"><span style="color:#333333">                   </span></span><span style="color:#993399"><span style="color:#993399">CONST VOID *source,</span></span><span style="color:#333333"><span style="color:#333333">//to Copy the source address of the memory block</span></span><br><span style="color:#333333"><span style="color:#333333">                   </span></span><span style="color:#993399"><span style="color:#993399">size_t Length</span></span><span style="color:#333333"><span style="color:#333333">//number of bytes copied</span></span><br><span style="color:#333333"><span style="color:#333333">);</span></span></strong></span><span style="font-size:18px"><span style="font-size:18px"><strong><span style="color:#333333">This function is used to copy data to mapped Memory. </span></strong></span></span></p><p><span style="font-size:18px; color:#cc6600"><span style="font-size:18px; color:#cc6600"><strong>Open the mapping object:</strong></span></span><span style="font-size:18px"><strong><span style="color:#333333"><span style="color:#333333">HANDLE</span></span><span style="color:#33cc00"><span style="color:#33cc00">openfilemapping</span></span><span style="color:#333333"><span style="color:#333333">(</span></span><br><span style="color:#333333"><span style="color:#333333">                         </span></span><span style="color:#993399"><span style="color:#993399">DWORD dwdesiredaccess,</span></span><span style="color:#333333"><span style="color:#333333">//access Rights</span></span><br><span style="color:#333333"><span style="color:#333333">                         </span></span><span style="color:#993399"><span style="color:#993399">BOOL binherithandle,</span></span><span style="color:#333333"><span style="color:#333333">//inheritance settings, generally set to false</span></span><br><span style="color:#333333"><span style="color:#333333">                         </span></span><span style="color:#993399"><span style="color:#993399">LPCTSTR lpname</span></span><span style="color:#333333"><span style="color:#333333">//mapping Object Name</span></span><br><span style="color:#333333"><span style="color:#333333">);</span></span></strong></span><span style="font-size:18px"><span style="font-size:18px"><strong><span style="color:#333333">This function is used to open an existing mapping object. Returns a handle to the mapping Object. </span></strong></span></span><span style="font-size:18px; color:#333333"><span style="font-size:18px; color:#333333"><strong>  </strong></span></span><span style="font-size:18px"><span style="font-size:18px"><strong>3. <span style="color:#cc6600">kind:</span> <span style="color:#333333"> </span></strong></span></span><span style="font-size:18px"><span style="font-size:18px"><strong>Execute the PROCESS1 program in VC6.0 first. <span style="color:#333333"></span> <span style="color:#009900"> In the execution of the Process2 program:</span> </strong></span></span><span style="font-size:18px; color:#333333"><span style="font-size:18px; color:#333333"><strong></strong></span></span></p><p><p><strong>watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvbg92zwnvzgvszxnz/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/southeast "><br></strong><span style="font-size:18px"><strong><span style="color:#333333"></span> <span style="color:#33cc00">Execution effect:</span></strong></span><span style="font-size:18px; color:#333333"><strong><br></strong></span><span style="font-size:18px; color:#333333"><strong>Process1 program:</strong></span><span style="font-size:18px; color:#333333"><strong></strong></span><strong><span style="font-size:18px">process2 program:</span></strong><br><br><span style="font-size:18px"><strong><span style="color:#333333"><br></span></strong></span></p></p><p><p>"IPC interprocess communication three" memory-mapped files mapping file</p></p></span></span></span>

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.