Skip to main content
Create a shared memory region in one process, write data, open it from another, read it back.

Step 1: Create a writer

The writer process creates a shared region, writes a float value, and notifies any waiters.

Step 2: Create a reader

Run this in a separate terminal window while the writer is running.

Step 3: Verify

Run the writer first. Then run the reader in a separate terminal. The reader prints 42.0. Same value the writer wrote, same physical memory. No serialization, no socket, no file I/O.

What happened

  1. The writer called zinc_create("my-data", 4096), which called shm_open with O_CREAT | O_EXCL, then ftruncate to set the size, then mmap to map it.
  2. The reader called zinc_open("my-data"), which called shm_open without O_CREAT, then mmap to map the same pages.
  3. Both processes now have the same physical RAM pages in their address space.
  4. The writer wrote 42.0 to the first 4 bytes. The reader read those same bytes.
  5. The transfer cost was zero. There was nothing to transfer.

Next steps