Shared Memory Sample

I had previously prepared ObjectDeliverer samples on GitHub, but for shared memory, only the reading side was implemented, and the process wasn’t complete. So, I newly implemented the writing side as well.

Here, I will briefly introduce the contents of the sample.

Overview

In this sample, an image captured by SceneCapture2D is extracted from a TextureRenderTarget, and then displayed on another material via shared memory.

203fc2438cc4488ddf9567ad67496f63
  1. First, please open the SharedMemory level. sharedmemory1
  2. All implementation is within the Box Actor blueprint.

Reading Side Implementation

  1. Prepare a texture and material to hold the pixel buffer read from shared memory. sharedmemory2
  2. Generate an instance of ObjectDeliverer for reading shared memory and start the process. sharedmemory3

The shared memory buffer size is set to the image buffer size (800x450x4 bytes).

  1. Update the texture content in the ReceiveData event (an event that occurs when the content of the shared memory changes). sharedmemory4

Writing Side Implementation

  1. Prepare a buffer to hold the pixel buffer obtained from TextureRenderTarget.
  2. Generate an instance of ObjectDeliverer for writing to shared memory and start the process. sharedmemory3

The shared memory buffer size is set to the image buffer size (800x450x4 bytes).

sharedmemory4
  1. During the Tick event, extract the pixel buffer from TextureRenderTarget and write it to shared memory. sharedmemory4

Use Cases

In this example, it’s completed within a single process, so it doesn’t have much meaning. However, for instance, by preparing two UE4 projects, one responsible for writing to shared memory and the other for reading from shared memory, video transfer can be achieved.

Unlike TCP/IP or UDP, shared memory cannot transfer data over a network, but because of that, it can transfer large amounts of data at high speed, making it suitable for inter-process communication of heavy data like video.

Please try it out if you are interested.