ZeroAlloc.Collections
1.1.1
dotnet add package ZeroAlloc.Collections --version 1.1.1
NuGet\Install-Package ZeroAlloc.Collections -Version 1.1.1
<PackageReference Include="ZeroAlloc.Collections" Version="1.1.1" />
<PackageVersion Include="ZeroAlloc.Collections" Version="1.1.1" />
<PackageReference Include="ZeroAlloc.Collections" />
paket add ZeroAlloc.Collections --version 1.1.1
#r "nuget: ZeroAlloc.Collections, 1.1.1"
#:package ZeroAlloc.Collections@1.1.1
#addin nuget:?package=ZeroAlloc.Collections&version=1.1.1
#tool nuget:?package=ZeroAlloc.Collections&version=1.1.1
ZeroAlloc.Collections
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>.Sharedand return buffers on disposal - Ref Struct Variants — stack-only types with compile-time lifetime enforcement and
ref Tindexers - Heap Variants — class-based counterparts that implement
IDisposable,IList<T>, andIReadOnlyList<T>for use in async methods and DI - Span Accessors —
AsSpan()andAsReadOnlySpan()on every collection for zero-copy interop - Source Generators — emit type-specific collections, pooled wrappers, and
ref structenumerators at compile time - Analyzer Diagnostics — build-time warnings for undisposed collections and accidental ref struct copies
- Multi-TFM — targets
netstandard2.1,net8.0, andnet9.0(allows ref structon .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 | 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 (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.