ZeroAlloc.Collections 2.0.1

dotnet add package ZeroAlloc.Collections --version 2.0.1
                    
NuGet\Install-Package ZeroAlloc.Collections -Version 2.0.1
                    
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.Collections" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ZeroAlloc.Collections" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="ZeroAlloc.Collections" />
                    
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.Collections --version 2.0.1
                    
#r "nuget: ZeroAlloc.Collections, 2.0.1"
                    
#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.Collections@2.0.1
                    
#: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.Collections&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=ZeroAlloc.Collections&version=2.0.1
                    
Install as a Cake Tool

ZeroAlloc.Collections

NuGet Build codecov License: MIT AOT GitHub Sponsors

Pooled and stack-only counterparts to List<T>, Dictionary<TKey,TValue>, Stack<T> and Queue<T> whose ref struct forms add, look up and enumerate with 0 B allocated, NativeAOT-ready.

Why ZeroAlloc.Collections

  • 0 B on the hot path, asserted in CI. The ref struct collections add, look up and enumerate with 0 B allocated per call; AllocationTests fails CI if any of them allocates.
  • Faster than the BCL as well. Adding 1,000 items to a PooledList<int> takes 0.63× the time of List<int>, which allocates 8,424 B in the same run. Stacks, queues and dictionaries take 0.6–0.8×, and a RingBuffer<int> takes 0.47× a pre-sized Queue<int>.
  • Works under NativeAOT and trimming. No reflection and no runtime code generation; every PR publishes and runs an AOT sample.
  • Compile-time diagnostics instead of runtime surprises. ZAC001 warns when a pooled collection is never disposed, so a buffer that would never return to the pool is a build warning.

Install

dotnet add package ZeroAlloc.Collections

Quick start

using ZeroAlloc.Collections;

string[] order = ["apple", "pear", "apple", "kiwi"];

// Rents its entries from ArrayPool<T>.Shared and returns them on Dispose.
using var prices = new SpanDictionary<string, decimal>(capacity: 16);
prices.Add("apple", 0.50m);
prices.Add("pear", 0.75m);

// Lives on the stack: no heap allocation at all.
var basket = new FixedSizeList<decimal>(stackalloc decimal[8]);
foreach (var item in order)
    if (prices.TryGetValue(item, out var price)) basket.Add(price);

decimal total = 0;
foreach (var p in basket) total += p;
Console.WriteLine($"{basket.Count} items, {total}"); // 3 items, 1.75

What you get

Type Ref Struct Heap Variant Description
PooledList<T> Yes HeapPooledList<T> Pooled-backed growable list
RingBuffer<T> Yes HeapRingBuffer<T> Fixed-capacity circular buffer
SpanDictionary<TKey,TValue> Yes HeapSpanDictionary<TKey,TValue> Open-addressing hash map
PooledStack<T> Yes HeapPooledStack<T> Pooled-backed LIFO stack
PooledQueue<T> Yes HeapPooledQueue<T> Pooled-backed FIFO queue
FixedSizeList<T> Yes HeapFixedSizeList<T> Stack-allocated fixed-capacity list
ConcurrentHeapSpanDictionary<TKey,TValue> No — Thread-safe, coarse-locked, pooled hash map
  • Two forms of each: a ref struct for synchronous hot paths, and a Heap* class for fields, async code and APIs that take IList<T>, IReadOnlyCollection<T> or IDictionary<TKey,TValue>.
  • Span<T> access to the list and stack contents for zero-copy loops.
  • Source generators that emit type-specific collections from [ZeroAllocList(typeof(T))]. See source generators.
  • Targets net10.0 and net11.0.

Performance

BenchmarkDotNet, N = 1,000. Time is the same-run ratio against the BCL type; allocations are exact.

Workload BCL type ZeroAlloc time BCL alloc ZeroAlloc alloc
Add N items List<int> 0.63× 8,424 B 0 B
Push and pop N items Stack<int> 0.62× 8,424 B 0 B
Enqueue and dequeue N items Queue<int> 0.79× 8,432 B 0 B
Write and read N items, capacity known Queue<int> 0.47× 4,064 B 0 B

The Heap* classes enumerate with public struct enumerators, so their foreach allocates nothing either. Every workload, with the full numbers: docs/performance.md.

Learn more

License

MIT. See LICENSE.

Product Compatible and additional computed target framework versions.
.NET 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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net11.0

    • No dependencies.

NuGet packages (16)

Showing the top 5 NuGet packages that depend on ZeroAlloc.Collections:

Package Downloads
ZeroAlloc.Rest

Source-generated, AOT-compatible REST client for .NET

ZeroAlloc.Scheduling.InMemory

In-memory job store for ZeroAlloc.Scheduling — use in tests.

ZeroAlloc.Outbox.InMemory

In-memory store adapter for ZeroAlloc.Outbox (testing).

ZeroAlloc.EventSourcing

Source-generated event-sourced aggregates for .NET. Zero-allocation event dispatch, AOT-safe.

BlazorNative.Renderer

The BlazorNative renderer: drives Blazor's RenderTree diffing into a native widget tree and emits binary UI patch frames for platform shells. NativeAOT/trim-compatible.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 0 11/22/2026
2.0.0 4 11/22/2026
1.3.1 2,777 11/17/2026
1.3.0 9,387 11/11/2026
1.2.5 14,328 10/29/2026
1.2.4 12,376 10/18/2026
1.2.3 6,079 10/16/2026
1.2.2 2,069 10/15/2026
1.2.1 5,949 10/11/2026
1.2.0 5,237 10/10/2026
1.1.11 5,092 9/30/2026
1.1.10 4,751 9/28/2026
1.1.9 3,129 9/27/2026
1.1.8 4,295 9/25/2026
1.1.7 3,128 9/20/2026
1.1.5 20,246 9/19/2026
1.1.2 11,273 5/12/2026
1.1.1 304 5/3/2026
1.1.0 191 5/1/2026
Loading failed