ZeroAlloc.Collections 1.1.1

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

ZeroAlloc.Collections

NuGet Build License: MIT AOT GitHub Sponsors

ZeroAlloc.Collections is a high-performance, zero-allocation collections library for .NET. It provides six collection types — each available as a ref struct for stack-only scenarios and as a heap-allocated class for use in async code, fields, and DI containers. All collections rent their backing storage from ArrayPool<T>.Shared, return it on Dispose(), and expose Span<T> accessors for tight inner loops. Source generators are included for emitting specialized, type-specific collection implementations at compile time.

Install

dotnet add package ZeroAlloc.Collections

Example

PooledList

using ZeroAlloc.Collections;

using var list = new PooledList<int>(capacity: 64);

list.Add(1);
list.Add(2);
list.Add(3);

foreach (var item in list)
{
    Console.WriteLine(item);
}

The list rents from ArrayPool<T>.Shared on construction and returns the buffer when Dispose() runs — zero heap allocation for the backing array.

RingBuffer

using ZeroAlloc.Collections;

using var ring = new RingBuffer<string>(capacity: 4);

ring.TryWrite("alpha");
ring.TryWrite("beta");
ring.TryWrite("gamma");

while (ring.TryRead(out var item))
{
    Console.WriteLine(item); // alpha, beta, gamma
}

A fixed-capacity circular buffer suitable for producer/consumer queues, telemetry windows, and bounded logging.

Features

  • Zero Allocation — all pooled collections rent from ArrayPool<T>.Shared and return buffers on disposal
  • Ref Struct Variants — stack-only types with compile-time lifetime enforcement and ref T indexers
  • Heap Variants — class-based counterparts that implement IDisposable, IList<T>, and IReadOnlyList<T> for use in async methods and DI
  • Span AccessorsAsSpan() and AsReadOnlySpan() on every collection for zero-copy interop
  • Source Generators — emit type-specific collections, pooled wrappers, and ref struct enumerators at compile time
  • Analyzer Diagnostics — build-time warnings for undisposed collections and accidental ref struct copies
  • Multi-TFM — targets netstandard2.1, net8.0, and net9.0 (allows ref struct on .NET 9)
  • Native AOT Compatible — no reflection, no dynamic code generation

Collections

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

Documentation

Page Description
Getting Started Install and use your first collection in five minutes
PooledList Growable list backed by ArrayPool<T>
RingBuffer Fixed-capacity circular buffer
SpanDictionary Open-addressing hash map with Span accessors
PooledStack & PooledQueue LIFO stack and FIFO queue with pooled storage
FixedSizeList Stack-allocated fixed-capacity list
Source Generators Emit type-specific collections at compile time
Diagnostics Analyzer warnings and error reference
Performance Benchmark results and zero-alloc design internals
Testing Unit-test collections with xUnit

License

MIT

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 is compatible.  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 is compatible.  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 was computed.  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.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (8)

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

Package Downloads
ZeroAlloc.Resilience

Source-generated, zero-allocation resilience policies for .NET. Add [Retry], [Timeout], [RateLimit], and [CircuitBreaker] to an interface; the generator emits a proxy composing all policies in declaration order. AOT-safe.

ZeroAlloc.Scheduling.InMemory

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

ZeroAlloc.Outbox.InMemory

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

AI.Sentinel

Security monitoring middleware for IChatClient — prompt injection, hallucination, and operational anomaly detection with an intervention engine.

ZeroAlloc.Rest

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

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.1 151 5/3/2026
1.1.0 138 5/1/2026
1.0.1 235 4/29/2026
1.0.0 301 4/28/2026
0.1.7 2,014 4/28/2026
0.1.6 749 4/24/2026
0.1.5 596 4/1/2026
0.1.4 217 4/1/2026
0.1.3 905 3/31/2026
0.1.1 94 3/31/2026