Shared Memory Functions

RTSS shared memory objects allow you to share blocks of data among multiple processes, including RTSS processes and Win32 processes. To do this, a thread in each process must have its own process-relative handle to a single RTSS 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

In order 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.

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 shared memory that already exists, the behavior differs between RTX and Windows.

  • When you make the call from an RTX process, the size of the shared memory that is returned is equal to the amount that was created by the RtCreateSharedMemory call that first created the shared memory object.
  • When you make the call from a Windows process, the amount of memory that is returned is equal to the requested amount. If the requested amount of memory is greater than the current size of the shared memory object, the object's size is increased to the requested size and that amount of memory is returned.

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. When a process is finished with the shared memory it should close the handle to the shared memory object.

 

See Also

IntervalZero.com | Support | Give Feedback