Skip to main content
The C# adapter uses P/Invoke (Platform Invocation Services) to call the Zinc C ABI. It exposes a Span<byte> over the shared mapping. Keep the region open while using that span. The source targets .NET 8.

Installation

Build the core from a source checkout, then set up the adapter:

SharedRegion

Create

Creates a new region. Throws InvalidOperationException on failure.

Open

Opens an existing region.

Bytes

Returns a Span<byte> backed by the shared memory mapping. No copying occurs.

Notify

Wait

Returns true on notification, false on timeout.

Dispose

Complete example

This uses two handles in one process. For separate processes, keep the creator running until the reader finishes. TryWait() consumes a pending notification without blocking.

P/Invoke details

The native function declarations:
The Bytes() method creates a Span<byte> from the native pointer and capacity using new Span<byte>((void*)ptr, (int)capacity). This is an unsafe context but the adapter encapsulates it. The span is valid only while the SharedRegion handle is not disposed. The zinc_core library must be on the system’s library search path, or placed in the same directory as the application executable.