Note that there are some explanatory texts on larger screens.

plurals
  1. POSplitting shared memory?
    primarykey
    data
    text
    <p>A block of shared memory is allocated using <code>CreateFileMapping()</code> and the handle to it is given. Some data were written using <code>MapViewOfFile()</code> -- call it 'source'</p> <p>Now I wish to split the shared memory into many small blocks and to get the handles to them.<br> Is there a way to do that while not calling <code>CreateFileMapping()</code> again and copying from 'source'?</p> <p><code>OpenFileMapping()</code> and <code>MapViewOfFile()</code> with appropriate offsets will work but the problem is, in that case the process that calls <code>OpenFileMapping()</code> get to have access to data written in 'source' by other processes and they might be corrupted by using a wrong offset.</p> <p>Long story short, I'm looking for something like <code>OpenFileMapping(String name, UINT **offset**, ...)</code></p> <hr> <p>The last sentence was misleading.</p> <p>What I'm really trying to do is something like this:</p> <pre><code>&lt;Host process&gt; HANDLE hShm = CreateFileMapping(INVALID_HANDLE_VALUE, ..., "shm"); void* pShm = MapViewOfFile(hShm); UINT numShms = *(UINT*)pShm; // first 4 bytes stores number of shared memory blocks HANDLE *hShmSplit = new HANDLE[numShms]; for(size_t i=0; i&lt;numShms; i++) { TCHAR shmName[32]; wsprintf(shmName, "shm%d", i); // suppose offset is set pShm+=offset; hShmSplit[i] = *CreateFileMappingFromExistingMapping*(pShm, shmName); } CloseHandle(hShm); // no longer used &lt;Client process&gt; TCHAR* shmName="shm1"; HANDLE hShm = OpenFileMapping(shmName); LPVOID p = MapViewOfFile(hShm); // use shared memory // Now the client process has access to shm1 but not to shm2, shm3, or other shm_x's. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload