ZeroAlloc.Memory 0.1.0

dotnet add package ZeroAlloc.Memory --version 0.1.0
                    
NuGet\Install-Package ZeroAlloc.Memory -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ZeroAlloc.Memory" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAlloc.Memory" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="ZeroAlloc.Memory" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ZeroAlloc.Memory --version 0.1.0
                    
#r "nuget: ZeroAlloc.Memory, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ZeroAlloc.Memory@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ZeroAlloc.Memory&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAlloc.Memory&version=0.1.0
                    
Install as a Cake Tool

ZeroAlloc.Memory

CI NuGet License: MIT

Zero-allocation unmanaged memory allocators, linear arenas, virtual-memory mirrored ring buffers, and native collections for .NET 10 and netstandard2.1 (Unity / client / server).

Compiled as AnyCPU and tested in CI across 64-bit x64 and ARM64 (linux-x64, linux-arm64, win-x64, osx-arm64).


Origin & Intent

ZeroAlloc.Memory was originally built as the memory and IPC foundation for a high-tickrate distributed game/simulation engine (Echoes of Bathala) where:

  • Gen0/Gen2 GC pauses in hot simulation and networking loops were unacceptable,
  • Variable-length ring buffers needed contiguous Span<byte> reads/writes across wrap-around boundaries without split copies, and
  • A single memory foundation had to run identically across .NET 10 Linux servers (x64/ARM64) and netstandard2.1 Unity clients.

Installation

dotnet add package ZeroAlloc.Memory

When to Use (and When NOT to Use)

Use ZeroAlloc.Memory When… Do NOT Use When…
Standard ArrayPool<T>, Dictionary<K,V>, or Channel<T> causes measurable GC pauses in hot loops. Standard .NET BCL collections already meet your latency budget.
You store unmanaged structs or raw byte frames with deterministic tick/frame lifetimes. You need to store managed reference types (class, string).
You have strictly 1P/1C (SpscRing, MirroredSpscRing) or NP/1C (BoundedMpscRing, MirroredMpscRing) thread topologies. You have multiple concurrent consumers (MPMC is intentionally excluded).

See the full Collections & Arenas Decision Guide and Architecture & Memory Model.


Safety Contract & Known Limitations

  1. 64-Bit Process Required: Built as AnyCPU for x64 and ARM64 portability; 32-bit processes (x86/arm32) are unsupported and throw PlatformNotSupportedException in PageAllocator.
  2. Manual Lifetime (IDisposable): Value-type native handles and wrappers do not rely on GC finalizers for hot-path cleanup. Failing to call Dispose() leaks unmanaged/virtual memory.
  3. Thread-Topology Guarantees: SpscRing and MirroredSpscRing are strictly Single-Producer / Single-Consumer. Calling TryEnqueue/TryWrite from multiple threads requires BoundedMpscRing or MirroredMpscRing.
  4. Debug vs. Release Guards: UnmanagedPage / DebugMemoryGuard trailing canaries (0xDEADBEEF) catch buffer overruns in Debug builds and compile out to zero overhead in Release.

Quick Start

using Memory.Arena;
using Memory.Collections.Spsc;

// 1. Frame/tick-scoped linear arena (0 GC allocations)
using var arena = new UnmanagedLinearArena(capacityBytes: 64 * 1024);
int* buffer = arena.Allocate<int>(128);
buffer[0] = 42;

// 2. Cache-padded SPSC ring buffer (strictly 1 producer, 1 consumer)
using var ring = new SpscRing<long>(capacity: 1024);
ring.TryEnqueue(123456L);
ring.TryDequeue(out long value);

Benchmarks (.NET 10 X64, 0 B Managed Allocation)

FlatMap vs Dictionary Latency

  • FlatMap / NativeFlatMap vs Dictionary<K,V> (10,000 keys): 276 µs vs 759 µs on hits (2.75× faster), 175 µs vs 855 µs on in-place mutation (4.88× faster), 0 B allocated. (Note: dense full-table iteration remains faster in Dictionary — see full tradeoffs.)
  • UnmanagedLinearArena (10,000 batch slices): 4,101 ns (0.41 ns/item, 0 B allocated).
  • SpscRing (64B zero-copy round-trip): 269.8 ns, 0 B allocated.

Full BenchmarkDotNet tables & reproduction commands: docs/benchmarks/README.md


Building, Testing & Benchmarking

# Run full unit & concurrency stress suite (223 tests)
dotnet test -c Release

# Verify netstandard2.1 compatibility
dotnet build src/Memory/Memory.csproj -c Release -f netstandard2.1

# Run BenchmarkDotNet suite
dotnet run --project benchmark/Memory.Benchmark -c Release -- --filter *

License

MIT © 2026 Markism-JA

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 0 11/24/2026