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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Utils.PooledStringBuilders" Version="4.0.29" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.PooledStringBuilders" Version="4.0.29" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Utils.PooledStringBuilders" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Utils.PooledStringBuilders --version 4.0.29
                    
#r "nuget: Soenneker.Utils.PooledStringBuilders, 4.0.29"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Utils.PooledStringBuilders@4.0.29
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Utils.PooledStringBuilders&version=4.0.29
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.PooledStringBuilders&version=4.0.29
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image 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) where T : ISpanFormattable
  • AppendSpan(int length) — reserve and write directly into the buffer
  • Insert(...), Shrink(int), AppendLine(...), AppendSeparatorIfNotEmpty(char)
  • Length, Capacity, AsSpan(), EnsureCapacity(int), Clear()
  • ToString() — create a string without disposing the builder
  • ToStringAndDispose(bool clear = false) — create a string and return the buffer
  • Dispose() / Dispose(bool clear)

Notes

  • PooledStringBuilder is a stack-only ref struct; it cannot be boxed, captured, stored in a normal field, or kept across await.
  • 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 by ref when a helper must mutate the same builder.
  • Dispose exactly once, either through using, Dispose, or ToStringAndDispose. Do not use ToStringAndDispose and then dispose a copied or aliased value.
  • AppendSpan(length) immediately increases Length and 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.
  • AppendLine appends \n, not Environment.NewLine.
  • Clear() resets the logical length but does not zero the array. Use Dispose(clear: true) or ToStringAndDispose(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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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 0 8/30/2026
4.0.28 7,030 8/29/2026
4.0.27 362,751 7/27/2026
4.0.26 175,590 7/16/2026
4.0.25 259,076 6/18/2026
4.0.22 505,626 4/23/2026
4.0.21 243,890 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
Loading failed

Clarify pooled string builder ownership