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.

The C# adapter uses P/Invoke (Platform Invocation Services) to call the Zinc C ABI. It provides a safe Span<byte> wrapper over the shared memory mapping.

Installation

dotnet add package Zinc
Requires .NET 6 or later.

SharedRegion

using Zinc;

Create

var region = SharedRegion.Create("my-data", (nuint)4096);
Creates a new region. Throws InvalidOperationException on failure.

Open

var region = SharedRegion.Open("my-data");
Opens an existing region.

Bytes

Returns a Span<byte> backed by the shared memory mapping. No copying occurs.
Span<byte> bytes = region.Bytes();
BitConverter.GetBytes(3.14f).CopyTo(bytes);
float val = BitConverter.ToSingle(bytes);

Notify

region.Notify();

Wait

bool ok = region.Wait(timeoutMs: 1000);
Returns true on notification, false on timeout.

Dispose

region.Dispose();
using (var region = SharedRegion.Open("my-data")) {
    Span<byte> bytes = region.Bytes();
    // region is disposed when the block exits
}

Complete example

using Zinc;

// Writer
var writer = SharedRegion.Create("csharp-channel", (nuint)4096);
var bytes = writer.Bytes();
BitConverter.GetBytes(42.0).CopyTo(bytes);
writer.Notify();
Thread.Sleep(2000);
writer.Dispose();

// Reader (separate process)
var reader = SharedRegion.Open("csharp-channel");
if (reader.Wait(3000)) {
    var data = reader.Bytes();
    double val = BitConverter.ToDouble(data);
    Console.WriteLine($"read: {val}"); // 42.0
}
reader.Dispose();

P/Invoke details

The native function declarations:
[DllImport("zinc_core")]
static extern int zinc_create(string name, nuint capacity, out nint handle);

[DllImport("zinc_core")]
static extern int zinc_open(string name, out nint handle);

[DllImport("zinc_core")]
static extern nint zinc_ptr(nint handle);

[DllImport("zinc_core")]
static extern nuint zinc_capacity(nint handle);

[DllImport("zinc_core")]
static extern void zinc_close(nint handle);

[DllImport("zinc_core")]
static extern void zinc_notify(nint handle);

[DllImport("zinc_core")]
static extern int zinc_wait(nint handle, uint timeoutMs);
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.