/dotnext-skills:dotnext-memoryfrom .NEXT
Provides allocation-free memory routines from DotNext packages: SpanOwner, BufferWriterSlim, PoolingBufferWriter, PoolingArrayBufferWriter, SparseBufferWriter, and MemoryAllocator abstraction. Use to reduce allocations in .NET hot paths, replace StringBuilder/ArrayPool code, or make allocation strategy configurable.
Ships in .NEXT. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
DotNext and DotNext.Unsafe the project references (.csproj or
Directory.Packages.props). This skill describes 6.x. For older versions, verify each
member you use against the XML docs/IntelliSense of the referenced version.using shown next to each type.Most of the types are in DotNext package. In case of unmanaged memory allocations, add DotNext.Unsafe dependency as well.
SpanOwner<T> (DotNext.Buffers) data type.
using. When the length exceeds the threshold, SpanOwner<T> rents the memory from the pool, and Dispose returns it. For a stack-allocated span, Dispose does nothing.Unsafe.SizeOf<T>() for other element types.using DotNext.Buffers;
public static void Encode(ReadOnlySpan<char> input, Stream output, Encoding encoding)
{
const int stackallocThreshold = 512; // in bytes; keep it small, the stack is limited
int maxByteCount = encoding.GetMaxByteCount(input.Length);
using SpanOwner<byte> buffer = (uint)maxByteCount <= (uint)stackallocThreshold
? stackalloc byte[maxByteCount]
: new SpanOwner<byte>(maxByteCount);
var bytesWritten = encoding.GetBytes(input, buffer.Span);
output.Write(buffer.Span.Slice(0, bytesWritten));
}
DotNext.Buffers.BufferWriterSlim<T> type in combination with extension methods from DotNext.Buffers.Text.CharBuffer class instead of System.Text.StringBuilder in synchronous code because its initial buffer can be allocated on the stack. If the buffer overflows, the writer uses memory allocator to rent the memory (by default it uses ArrayPool<T>.Shared). String interpolation for this type is exposed by the Interpolate extension method from DotNext.Text.StringInterpolation class.
stackalloc char[...] for BufferWriterSlim<char>.Interpolate outside of the try block: calling it on a BufferWriterSlim<char> local inside try/finally fails to compile (CS8347/CS8350), and using var writer is not allowed either (CS1657, a using variable can't be passed by ref). If Interpolate throws, the rented buffer is not returned to the pool, which is harmless.WrittenSpan becomes invalid after Dispose(). Consume or copy it before.using DotNext.Buffers;
using DotNext.Text;
var writer = new BufferWriterSlim<char>(stackalloc char[256]);
writer.Interpolate($"Hello, {name}!");
try
{
ConsumeWrittenChars(writer.WrittenSpan);
}
finally
{
writer.Dispose();
}
Consider PoolingBufferWriter<T> (DotNext.Buffers) for async scenarios, where BufferWriterSlim<T> cannot be applied because it's ref struct. Set the expected upper bound of the written data via the Capacity init-only property, because the constructor only accepts the memory allocator: new PoolingBufferWriter<byte>(allocator) { Capacity = 4096 }. The buffer grows automatically in case of overflow, but each growth rents a larger buffer, copies the written data and returns the smaller buffer to the pool, where it remains retained. Frequent growth therefore costs copying and inflates the pool, so a good initial capacity matters.
PoolingArrayBufferWriter<T> (DotNext.Buffers) instead when the consumer needs the written data as an array: its WrittenArray property returns ArraySegment<T>, for example to pass to an API that accepts byte[] with offset and count. It rents arrays from ArrayPool<T>.Consider SparseBufferWriter<T> (DotNext.Buffers) if there is no way to guess the initial capacity, and the contiguous buffer is not a requirement. It chains chunks instead of growing a single buffer, so it never copies the written data on growth. The written memory can be enumerated chunk by chunk (foreach (ReadOnlyMemory<T> chunk in writer)), copied with CopyTo, or obtained as System.Buffers.ReadOnlySequence<T> through its ISupplier<ReadOnlySequence<T>> implementation. This type is not limited to bytes in contrast to RecyclableMemoryStream from Microsoft.IO.RecyclableMemoryStream package.
Write/Add methods only. Its IBufferWriter<T> members are implemented explicitly because using them can leave holes in the sparse buffer.Abstract away memory rental and allocation by using MemoryAllocator<T> delegate (DotNext.Buffers). It can be passed to the types mentioned above, so your application can be configured to use one of the predefined allocation strategies:
System.Buffers.ArrayPool<T>.Shared which is exposed by MemoryAllocator<T>.Default static propertyMemoryAllocator<T>.Array static propertyMemoryAllocator<T>.Unmanaged static extension property, which requires a reference to DotNext.Unsafe packageArrayPool<T> or MemoryPool<T> can be converted with the ToAllocator() extension methodWhat SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
dotnet, allocation-free, memory-management, spanowner, buffer-writer
4 skills in this plugin
/dotnext-concurrencyConcurrent data structures and allocation-free async building blocks from the DotNext.Threading NuGet package - AsyncLazy, TaskCompletionPipe, reusable ValueTaskCompletionSource, CancellationTokenMultiplexer, AsyncCounter (throttling), AsyncStateTracker, distributed leases, BoundedObjectPool and the SIEVE-based RandomAccessCache (managed and unmanaged-memory variants). Use when replacing Lazy<T> or Lazy<Task<T>> with async initialization; when reducing allocations of TaskCompletionSource, linked CancellationTokenSource or Task.WhenEach in hot paths; when implementing rate limiting, change notification streams, an object pool, an LRU/concurrent cache (including a large cache that puts pressure on GC), or a distributed lease./dotnext-coreCore types from the DotNext NuGet package - Optional<T> and Result<T> monads, Optional JSON serialization (PATCH DTOs with omitted fields), Timestamp, EnumType attribute lookup, ConsoleLifetimeTokenSource, TypeMap/ConcurrentTypeMap, LocalReference and UserData. Use when expressing absent values or errors without exceptions; when distinguishing undefined and null JSON fields; when measuring elapsed time or tracking deadlines; when reading attributes of enum members; when handling console app shutdown (Ctrl+C, SIGTERM) without a generic host; when a dictionary is keyed by System.Type; when a ref field to a ref struct is needed; or when attaching data to objects via ConditionalWeakTable./dotnext-threadingAsync synchronization primitives from the DotNext.Threading NuGet package - async exclusive and reader/writer locks (with sync acquisition for mixed callers), auto/manual reset events, countdown event, barrier, AsyncTrigger, awaiting WaitHandle/CancellationToken, and custom primitives via QueuedSynchronizer<T>. Use when writing async .NET code that needs mutual exclusion or signaling without blocking threads, or that must await a WaitHandle or a CancellationToken; and when converting lock/Monitor, Monitor.Wait/Pulse, ReaderWriterLockSlim, ManualResetEventSlim, AutoResetEvent, CountdownEvent, Barrier or WaitHandle.WaitOne to async, e.g. after "CS1996 cannot await in the body of a lock statement".npx claudepluginhub dotnet/dotnext --plugin dotnext-skillsOther plugins' skills for the same job