A high-performance, stack-only string builder that rents its underlying buffer from ArrayPool instead of allocating new arrays. Designed for short-lived string construction.
$ dotnet add package Soenneker.Utils.PooledStringBuilders
Soenneker.Utils.PooledStringBuildersTiny, fast ref struct string builder.
Backed by ArrayPool<char>. Low allocations. Short-lived use.
dotnet add package Soenneker.Utils.PooledStringBuilders
using Soenneker.Utils.PooledStringBuilders;
using var sb = new PooledStringBuilder(128);
sb.Append("Hello, ");
sb.Append(name);
sb.Append(' ');
sb.Append(id); // ISpanFormattable path, no boxing
sb.AppendLine();
string s = sb.ToString(); // returns string + returns buffer
new PooledStringBuilder(int capacity = 128)Append(char), Append(string?), Append(ReadOnlySpan<char>)Append<T>(T value, ReadOnlySpan<char> fmt = default, IFormatProvider? prov = null) where T : ISpanFormattableAppendSpan(int length) → write directly into the bufferAppendLine(), AppendSeparatorIfNotEmpty(char)Length, Capacity, Clear()ToString() (keep using; you must Dispose() later)ToStringAndDispose(bool clear = false) (one-shot finish)Dispose() / Dispose(bool clear)ref struct → stack-only. Don’t capture, box, store in fields, or cross await.using should be used, or there is ToStringAndDispose(). Don't use both.ToStringAndDispose(clear: true) to zero the array before returning to the pool.