SharedRegion lives in the core crate and exports directly for Rust projects.
Installation
Build the core from a source checkout, then set up the adapter:SharedRegion
create
Creates a new region. Thename must match [a-zA-Z0-9_-]+. The capacity must be a multiple of the system page size (typically 4096).
Ok(SharedRegion) on success, or Err(ZincError).
open
Opens an existing region by name. Validates the header magic and version.as_ptr
Returns a raw*mut u8 pointing to the data area (first byte after the header page).
capacity
Returns the usable size in bytes.notify
Atomically increments the notification sequence counter and wakes all waiters.wait
Blocks until the notification counter changes, or the timeout expires.Ok(()) on notification, Err(ZincError::TimedOut) on timeout, or Err(ZincError) for other errors.
try_wait
Consumes a pending notification without blocking. Returnsfalse if the counter has not changed since this handle’s last observation.
Drop
Regions close automatically whenSharedRegion drops. If the handle is the creator, the name is unlinked. Openers keep their existing mappings until they close.
Data access
write_at(offset, data), read_at(offset, buf), and write_bytes(offset, value, count) check the entire range before copying or filling bytes. Invalid ranges return ZincError::OutOfBounds without changing either buffer. An empty range at capacity() is valid.
unsafe: prevent concurrent access to bytes being written and concurrent writes to bytes being read. Source and destination buffers must not overlap. Copying bytes does not send a notification; call notify() when the update is ready.
Raw pointers require bounds checks and synchronization by the caller. A successful wait publishes preceding writes but does not keep a producer from overwriting data during a read. See notify and wait for the coordination rules.
Working with the header
RegionHeader is exported for advanced use but you rarely need it. It lives at the base of mapped memory and you can access it with unsafe pointer arithmetic. SharedRegion covers most use cases.
Ring
RingStorage owns an initialized queue of u64 values. Capacity must be a power of two greater than one. RingStorage::default() uses 256 slots.
push returns RingFull when it cannot reserve a slot; try_push returns a boolean. pop returns None when the next slot is not ready. Operations do not park the thread, but reservations can delay later items if a producer is descheduled before publishing.
len, is_empty, and remaining are snapshots. Under contention, len includes reserved slots that have not yet been published. Use push/pop results for flow control.
For shared memory, Ring::from_raw_with_capacity attaches to separately initialized storage. This is unsafe: the caller must provide aligned slots, valid atomic counters, and keep the mapping alive. The header’s ring counters are reserved; SharedRegion does not initialize a ring in its data area.
Run cargo bench -p zinc-core --bench ring to measure push/pop and producer contention. Contention measurements include thread startup for each batch of 4096 values.