Shared Memory Functions
Process shared memory objects allow you to share blocks of data among multiple processes. To do this, a thread in each process must have its own process-relative handle to a single Process shared memory object and its own process-relative pointer to a location where the virtual address of the mapping will be stored. These handles and pointers can be obtained by calling either RtCreateSharedMemory or RtOpenSharedMemory.
Using RtCreateSharedMemory
For several processes to use a shared memory object, the object must be first created using RtCreateSharedMemory. Other processes can then use the shared memory object's given name to map the shared memory object. RtCreateSharedMemory returns a handle and sets a location to the base address of the shared memory. A process can then write directly to that base address to share information with other processes accessing the shared memory.
- RtCreateSharedMemory fails if the amount of memory requested cannot be allocated. When RtCreateSharedMemory fails, no memory is mapped, and no handles are returned.
- RtCreateSharedMemory will default to RtOpenSharedMemory if a shared memory object of the same name already exists.
Using RtOpenSharedMemory
- RtOpenSharedMemory maps an already created shared memory object. After the shared memory object has been created by a process, additional processes may map the shared memory into their address spaces by calling RtOpenSharedMemory. RtOpenSharedMemory will fail if the named shared memory object does not exist.
- RtOpenSharedMemory returns a handle to the shared memory object and sets a location to the base address of the shared memory. A process can then write directly to that base address to share information with other processes accessing the shared memory.
When a process is finished with the shared memory it should close the handle to the shared memory object.