Shared Memory Functions
RTSS shared memory objects allow you to share blocks of data among multiple processes, including RTSS and Windows processes. To do this, a thread in each process must have its process-relative handle to a single RTSS shared memory object and its 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.
Note: If you use RtCreateSharedMemory with the same name but a different size to create existing shared memory, the behavior differs between wRTOS and Windows.
- When you make the call from a wRTOS process, the size of the returned shared memory is equal to the amount created by the RtCreateSharedMemory call that first created the shared memory object. If the requested amount of memory is less than the current size of the shared memory object, the object's size is decreased to the requested size, and that amount of memory is returned. If the requested amount of memory is greater than the current size of the shared memory object, the shared memory does not expand, and the API fails with invalid parameter.
- When you make the call from a Windows process, the API fails with invalid parameter.
Using RtOpenSharedMemory
- RtOpenSharedMemory maps an already created shared memory object. After a process has created the shared memory object, 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, the handle should be closed to the shared memory object.