Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mine-27913f41.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

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.
use zinc_core::SharedRegion;

let region = SharedRegion::create("my-data", 4096)?;
let ptr = region.as_ptr() as *mut f32;
unsafe { std::ptr::write(ptr, 42.0); }
region.notify();
// Keep region alive until reader has opened it
std::thread::sleep(std::time::Duration::from_secs(5));

Step 2: Create a reader

Run this in a separate terminal window while the writer is running.
use zinc_core::SharedRegion;

let region = SharedRegion::open("my-data")?;
let ptr = region.as_ptr() as *const f32;
let val = unsafe { std::ptr::read(ptr) };
println!("Read: {}", val); // 42.0
region.wait(5000); // blocks until next notification

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