Overview of ZString
masterZString is a zero-allocation StringBuilder designed for .NET Core and Unity. It aims to replace standard string operations to minimize memory allocations and avoid boxing of value types.
Key features include:
- Struct-based StringBuilder: Avoids allocating the builder object itself.
- Buffer Renting: Uses
ThreadStaticorArrayPoolfor write buffers. - Generic Append Methods:
Append<T>(T value)writes directly to the buffer, avoidingvalue.ToString()allocations. - Boxing-free Formatting:
AppendFormat<T1...T16>andConcat<T1...T16>avoid boxing struct arguments andToStringallocations. - Direct Buffer Access: Supports building both UTF-16 (
Span<char>) and UTF-8 (Span<byte>) directly. - Zero-Allocation Output: Can use the inner buffer to write directly to stringless APIs (e.g., Unity TextMeshPro's
SetCharArray), achieving completely zero allocation.