https://github.com/soenneker/soenneker.utils.pooledstringbuilders
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.
https://github.com/soenneker/soenneker.utils.pooledstringbuilders
csharp dotnet high performance pool pooled pooledstringbuilder pooledstringbuilders string stringbuilder util utils
Last synced: about 1 month ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/soenneker/soenneker.utils.pooledstringbuilders
- Owner: soenneker
- License: mit
- Created: 2025-09-15T01:27:51.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2026-03-10T04:58:08.000Z (about 1 month ago)
- Last Synced: 2026-03-10T10:16:43.102Z (about 1 month ago)
- Topics: csharp, dotnet, high, performance, pool, pooled, pooledstringbuilder, pooledstringbuilders, string, stringbuilder, util, utils
- Language: C#
- Homepage: https://soenneker.com
- Size: 177 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
[](https://www.nuget.org/packages/soenneker.utils.pooledstringbuilders/)
[](https://github.com/soenneker/soenneker.utils.pooledstringbuilders/actions/workflows/publish-package.yml)
[](https://www.nuget.org/packages/soenneker.utils.pooledstringbuilders/)
[](https://github.com/soenneker/soenneker.utils.pooledstringbuilders/actions/workflows/codeql.yml)
#  Soenneker.Utils.PooledStringBuilders
**Tiny, fast `ref struct` string builder.**
Backed by `ArrayPool`. Low allocations. Short-lived use.
## Install
```bash
dotnet add package Soenneker.Utils.PooledStringBuilders
```
## Example
```csharp
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
```
## Cheatsheet
* `new PooledStringBuilder(int capacity = 128)`
* `Append(char)`, `Append(string?)`, `Append(ReadOnlySpan)`
* `Append(T value, ReadOnlySpan fmt = default, IFormatProvider? prov = null)` where `T : ISpanFormattable`
* `AppendSpan(int length)` ? write directly into the buffer
* `AppendLine()`, `AppendSeparatorIfNotEmpty(char)`
* `Length`, `Capacity`, `Clear()`
* `ToString()` (keep using; you must `Dispose()` later)
* `ToStringAndDispose(bool clear = false)` (one-shot finish)
* `Dispose()` / `Dispose(bool clear)`
## Notes
* **`ref struct`** ? stack-only. Don�t capture, box, store in fields, or cross `await`.
* **Dispose when done.** `using` should be used, or there is `ToStringAndDispose()`. Don't use both.
* **Handling secrets?** Use `ToStringAndDispose(clear: true)` to zero the array before returning to the pool.
* Not thread-safe. Keep it short-lived and single-scope.