Transferring data through a memory-mapped file using Win32/WINAPI

前端 未结 3 785
别那么骄傲
别那么骄傲 2021-01-12 03:59

I need to transfer some data - char buffer[100000]; - to a child process which is started by me.

Right now I\'m using an ordinary file to do so, the par

3条回答
  •  清酒与你
    2021-01-12 04:14

    You can use an anonymous file mapping (David Heffernan's answer goes into more detail on this step) with handle inheritance / handle duplication. For example, pass the HANDLE from the parent process on the command-line, then in the child use DuplicateHandle to get a valid HANDLE in the child.

    The CreateFileMapping documentation says that

    Multiple processes can share a view of the same file by either using a single shared file mapping object or creating separate file mapping objects backed by the same file. A single file mapping object can be shared by multiple processes through inheriting the handle at process creation, duplicating the handle, or opening the file mapping object by name. For more information, see the CreateProcess, DuplicateHandle and OpenFileMapping functions.

    But it may be easier just to use a ramdisk.

提交回复
热议问题