VOOZH about

URL: https://www.nuget.org/packages/LinkDotNet.StringBuilder/

⇱ NuGet Gallery | LinkDotNet.StringBuilder 3.4.1




👁 Image
LinkDotNet.StringBuilder 3.4.1

dotnet add package LinkDotNet.StringBuilder --version 3.4.1
 
 
NuGet\Install-Package LinkDotNet.StringBuilder -Version 3.4.1
 
 
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="LinkDotNet.StringBuilder" Version="3.4.1" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LinkDotNet.StringBuilder" Version="3.4.1" />
 
Directory.Packages.props
<PackageReference Include="LinkDotNet.StringBuilder" />
 
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 LinkDotNet.StringBuilder --version 3.4.1
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: LinkDotNet.StringBuilder, 3.4.1"
 
 
#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 LinkDotNet.StringBuilder@3.4.1
 
 
#: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=LinkDotNet.StringBuilder&version=3.4.1
 
Install as a Cake Addin
#tool nuget:?package=LinkDotNet.StringBuilder&version=3.4.1
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

StringBuilder

👁 .NET
👁 Nuget
👁 GitHub tag

A fast and low allocation StringBuilder for .NET.

Getting Started

Install the package:

PM> Install-Package LinkDotNet.StringBuilder

Afterward, use the package as follow:

using LinkDotNet.StringBuilder; // Namespace of the package

using ValueStringBuilder stringBuilder = new();
stringBuilder.AppendLine("Hello World");

string result = stringBuilder.ToString();

There are also smaller helper functions, which enable you to use ValueStringBuilder without any instance:

string result1 = ValueStringBuilder.Concat("Hello ", "World"); // "Hello World"
string result2 = ValueStringBuilder.Concat("Hello", 1, 2, 3, "!"); // "Hello123!"

By default, ValueStringBuilder uses a rented buffer from ArrayPool<char>.Shared. You can avoid renting overhead with an initially stack-allocated buffer:

using ValueStringBuilder stringBuilder = new(stackalloc char[128]);

Note that this will prevent you from returning stringBuilder or assigning it to an out parameter.

What does it solve?

The dotnet version of the StringBuilder is an all-purpose version that normally fits a wide variety of needs. But sometimes, low allocation is key. Therefore I created the ValueStringBuilder. It is not a class but a ref struct that tries to allocate as little as possible. If you want to know how the ValueStringBuilder works and why it uses allocations and is even faster, check out this blog post. The blog goes into a bit more in detail about how it works with a simplistic version of the ValueStringBuilder.

What doesn't it solve?

The library is not meant as a general replacement for the StringBuilder built into .NET. You can head over to the documentation and read about the "Known limitations". The library works best for a small to medium length strings (not hundreds of thousands of characters, even though it can be still faster and performs fewer allocations). At any time, you can convert the ValueStringBuilder to a "normal" StringBuilder and vice versa.

The normal use case is to concatenate strings in a hot path where the goal is to put as minimal pressure on the GC as possible.

Documentation

More detailed documentation can be found here. It is really important to understand how the ValueStringBuilder works so that you did not run into weird situations where performance/allocations can even rise.

Benchmark

The following table compares the built-in StringBuilder and this library's ValueStringBuilder:

BenchmarkDotNet v0.14.0, macOS Sequoia 15.3.1 (24D70) [Darwin 24.3.0]
Apple M2 Pro, 1 CPU, 12 logical and 12 physical cores
.NET SDK 9.0.200
 [Host] : .NET 9.0.2 (9.0.225.6610), Arm64 RyuJIT AdvSIMD
 DefaultJob : .NET 9.0.2 (9.0.225.6610), Arm64 RyuJIT AdvSIMD


| Method | Mean | Error | StdDev | Ratio | Gen0 | Allocated | Alloc Ratio |
|-------------------- |----------:|---------:|---------:|------:|-------:|----------:|------------:|
| DotNetStringBuilder | 126.74 ns | 0.714 ns | 0.667 ns | 1.00 | 0.1779 | 1488 B | 1.00 |
| ValueStringBuilder | 95.69 ns | 0.118 ns | 0.110 ns | 0.76 | 0.0669 | 560 B | 0.38 |

For more comparisons, check the documentation.

Another benchmark shows that ValueStringBuilder allocates less memory when appending value types (such as int and double):

| Method | Mean | Error | StdDev | Gen0 | Gen1 | Allocated |
|------------------------------- |---------:|--------:|--------:|-------:|-------:|----------:|
| ValueStringBuilderAppendFormat | 821.7 ns | 1.29 ns | 1.14 ns | 0.4330 | - | 3.54 KB |
| StringBuilderAppendFormat | 741.5 ns | 5.58 ns | 5.22 ns | 0.9909 | 0.0057 | 8.1 KB |

Check out the for a more detailed comparison and setup.

Support & Contributing

Thanks to all contributors and people that are creating bug-reports and valuable input:

<a href="https://github.com/linkdotnet/StringBuilder/graphs/contributors"> <img src="https://contrib.rocks/image?repo=linkdotnet/StringBuilder" alt="Supporters" /> </a>

Product Versions Compatible and additional computed target framework versions.
.NET net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 is compatible.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 is compatible.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows 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 (13)

Showing the top 5 NuGet packages that depend on LinkDotNet.StringBuilder:

Package Downloads
DccUtils.TypeFormatting

Package Description

Reo.Core.Reports

Package Description

JsonhCs

JSON for Humans.

SystemCall

A command-parsing library inspired by Jinx.

Vigilance

2D Game Engine

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on LinkDotNet.StringBuilder:

Repository Stars
MeltyPlayer/MeltyTool
Multitool for viewing/extracting assets from various N64/GCN/3DS/PC games en-masse.
Version Downloads Last Updated
3.4.1 9,206 2/19/2026
3.4.0 134 2/18/2026
3.3.0 3,147 1/19/2026
3.2.0 4,362 10/31/2025
3.1.0 227 10/31/2025
3.0.0 268 10/30/2025
2.4.1 16,315 3/25/2025
2.4.0 22,161 2/21/2025
2.3.1 268 2/20/2025
2.3.0 316 2/16/2025
2.2.0 2,570 1/25/2025
2.1.0 587 1/14/2025
2.0.0 265 1/12/2025
1.22.0 475 12/18/2024
1.21.1 1,801 11/8/2024
1.21.0 2,107 9/20/2024
1.20.0 10,826 5/2/2024
1.19.1 398 4/19/2024
1.19.0 8,353 3/2/2024
1.18.6 5,389 11/3/2023
Loading failed