ZeroAlloc.Collections
1.2.3
dotnet add package ZeroAlloc.Collections --version 1.2.3
NuGet\Install-Package ZeroAlloc.Collections -Version 1.2.3
<PackageReference Include="ZeroAlloc.Collections" Version="1.2.3" />
<PackageVersion Include="ZeroAlloc.Collections" Version="1.2.3" />
<PackageReference Include="ZeroAlloc.Collections" />
paket add ZeroAlloc.Collections --version 1.2.3
#r "nuget: ZeroAlloc.Collections, 1.2.3"
#:package ZeroAlloc.Collections@1.2.3
#addin nuget:?package=ZeroAlloc.Collections&version=1.2.3
#tool nuget:?package=ZeroAlloc.Collections&version=1.2.3
ZeroAlloc.Collections
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 structcollections add, look up and enumerate with 0 B allocated per call;AllocationTestsfails CI if any of them allocates. - About 2× faster than the BCL for lists, stacks and dictionaries. Adding 1,000 items to a
PooledList<int>takes 0.51× the time ofList<int>, which allocates 8,424 B in the same run. - 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.
ZAC001warns 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 structfor synchronous hot paths, and aHeap*class for fields,asynccode and APIs that takeIList<T>,IReadOnlyCollection<T>orIDictionary<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
netstandard2.1,net8.0andnet9.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.51× | 8,424 B | 0 B |
| Push and pop N items | Stack<int> |
0.55× | 8,424 B | 0 B |
| Write and read N items, capacity known | Queue<int> |
2.40× | 4,064 B | 0 B |
RingBuffer<T> and PooledQueue<T> trade speed for allocation, and the Heap* classes allocate one
enumerator per foreach. Every workload, with the full numbers: docs/performance.md.
Learn more
- Documentation: collections.zeroalloc.net, including getting started, the cookbook and diagnostics.
- Related packages: ZeroAlloc.Inject and ZeroAlloc.Analyzers.
- Contributing: issues and pull requests are welcome on GitHub.
- CHANGELOG.
License
MIT. See LICENSE.
| Product | Versions 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. |
-
.NETStandard 2.1
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (17)
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. |
|
|
AI.Sentinel
Security monitoring middleware for IChatClient — prompt injection, hallucination, and operational anomaly detection with an intervention engine. |
|
|
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. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.3 | 0 | 10/16/2026 |
| 1.2.2 | 73 | 10/15/2026 |
| 1.2.1 | 4,003 | 10/11/2026 |
| 1.2.0 | 5,152 | 10/10/2026 |
| 1.1.11 | 5,066 | 9/30/2026 |
| 1.1.10 | 4,716 | 9/28/2026 |
| 1.1.9 | 3,106 | 9/27/2026 |
| 1.1.8 | 4,262 | 9/25/2026 |
| 1.1.7 | 3,097 | 9/20/2026 |
| 1.1.5 | 13,513 | 9/19/2026 |
| 1.1.2 | 10,758 | 5/12/2026 |
| 1.1.1 | 288 | 5/3/2026 |
| 1.1.0 | 174 | 5/1/2026 |
| 1.0.1 | 350 | 4/29/2026 |
| 1.0.0 | 434 | 4/28/2026 |
| 0.1.7 | 3,024 | 4/28/2026 |
| 0.1.6 | 2,743 | 4/24/2026 |
| 0.1.5 | 15,765 | 4/1/2026 |
| 0.1.4 | 264 | 4/1/2026 |