Soenneker.Utils.PooledStringBuilders
4.0.29
Prefix Reserved
dotnet add package Soenneker.Utils.PooledStringBuilders --version 4.0.29
NuGet\Install-Package Soenneker.Utils.PooledStringBuilders -Version 4.0.29
<PackageReference Include="Soenneker.Utils.PooledStringBuilders" Version="4.0.29" />
<PackageVersion Include="Soenneker.Utils.PooledStringBuilders" Version="4.0.29" />
<PackageReference Include="Soenneker.Utils.PooledStringBuilders" />
paket add Soenneker.Utils.PooledStringBuilders --version 4.0.29
#r "nuget: Soenneker.Utils.PooledStringBuilders, 4.0.29"
#:package Soenneker.Utils.PooledStringBuilders@4.0.29
#addin nuget:?package=Soenneker.Utils.PooledStringBuilders&version=4.0.29
#tool nuget:?package=Soenneker.Utils.PooledStringBuilders&version=4.0.29
Soenneker.Utils.PooledStringBuilders
Tiny, fast ref struct string builder.
Backed by ArrayPool<char>. Low allocations. Short-lived use.
Installation
dotnet add package Soenneker.Utils.PooledStringBuilders
Example
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(); // creates a string; using returns the buffer afterward
Use ToString() when the builder remains in scope and will be disposed separately. For a one-shot
finish without a using declaration:
var sb = new PooledStringBuilder();
sb.Append("value=");
sb.Append(value);
string result = sb.ToStringAndDispose();
Cheatsheet
new PooledStringBuilder(int capacity = 128)Append(char),Append(string?),Append(ReadOnlySpan<char>)Append<T>(T value, ReadOnlySpan<char> format = default, IFormatProvider? provider = null)whereT : ISpanFormattableAppendSpan(int length)— reserve and write directly into the bufferInsert(...),Shrink(int),AppendLine(...),AppendSeparatorIfNotEmpty(char)Length,Capacity,AsSpan(),EnsureCapacity(int),Clear()ToString()— create a string without disposing the builderToStringAndDispose(bool clear = false)— create a string and return the bufferDispose()/Dispose(bool clear)
Notes
PooledStringBuilderis a stack-onlyref struct; it cannot be boxed, captured, stored in a normal field, or kept acrossawait.- Do not copy the builder (
var copy = builder). Copies refer to the same rented array and can return it to the pool more than once. Pass it byrefwhen a helper must mutate the same builder. - Dispose exactly once, either through
using,Dispose, orToStringAndDispose. Do not useToStringAndDisposeand then dispose a copied or aliased value. AppendSpan(length)immediately increasesLengthand returns uninitialized pooled storage. Fill the entire span before reading or converting the builder, or previous pool contents could appear in the result.AsSpan()is valid only until the builder grows, changes, or is disposed. Do not retain it.AppendLineappends\n, notEnvironment.NewLine.Clear()resets the logical length but does not zero the array. UseDispose(clear: true)orToStringAndDispose(clear: true)when the pooled buffer contained secrets. The returned managed string is still immutable and cannot be securely erased.- The builder is not thread-safe. Keep it short-lived and confined to one synchronous scope.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 is compatible. 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. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (12)
Showing the top 5 NuGet packages that depend on Soenneker.Utils.PooledStringBuilders:
| Package | Downloads |
|---|---|
|
Soenneker.Extensions.Spans.Readonly.Chars
A collection of helpful ReadOnlySpan (char) extension methods |
|
|
Soenneker.Redis.Util
The general purpose utility library leveraging Redis for all of your caching needs |
|
|
Soenneker.Extensions.HttpContent
A collection of helpful HttpContent extension methods |
|
|
Soenneker.Utils.Dotnet
A utility library for the dotnet executable |
|
|
Soenneker.Extensions.Spans.ReadOnly.Strings
A collection of helpful ReadOnlySpan (string) extension methods |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.29 | 96 | 8/30/2026 |
| 4.0.28 | 15,900 | 8/29/2026 |
| 4.0.27 | 371,663 | 7/27/2026 |
| 4.0.26 | 175,592 | 7/16/2026 |
| 4.0.25 | 259,086 | 6/18/2026 |
| 4.0.22 | 505,626 | 4/23/2026 |
| 4.0.21 | 243,899 | 3/14/2026 |
| 4.0.16 | 114,855 | 3/10/2026 |
| 4.0.15 | 56,680 | 3/9/2026 |
| 4.0.14 | 688 | 3/9/2026 |
| 4.0.13 | 91,969 | 3/4/2026 |
| 4.0.12 | 144,338 | 2/21/2026 |
| 4.0.11 | 5,003 | 2/21/2026 |
| 4.0.10 | 92,320 | 2/4/2026 |
| 4.0.9 | 94,652 | 1/8/2026 |
| 4.0.8 | 18,017 | 1/2/2026 |
| 4.0.7 | 36,991 | 11/20/2025 |
| 4.0.6 | 24,965 | 10/29/2025 |
| 3.0.5 | 3,383 | 10/23/2025 |
| 3.0.4 | 35,801 | 9/16/2025 |
Clarify pooled string builder ownership