nfx-stringbuilder 0.7.0
Cross-platform C++20 library for zero-allocation string building with Small Buffer Optimization
Loading...
Searching...
No Matches
StringBuilder.h File Reference

High-performance string building with Small Buffer Optimization (SBO). More...

#include <cstdint>
#include <format>
#include <memory>
#include <string>
#include <string_view>
#include "nfx/detail/string/StringBuilder.inl"
Include dependency graph for StringBuilder.h:

Go to the source code of this file.

Classes

class  nfx::string::StringBuilder
 High-performance string builder with efficient memory management. More...

Macros

#define NFX_STRINGBUILDER_FORCE_INLINE   inline
 Cross-platform forced inline macro for critical hot-path methods.

Detailed Description

High-performance string building with Small Buffer Optimization (SBO).

Growable character buffer optimized for efficient string construction

StringBuilder Memory Architecture:

Memory Layout:
┌──────────────────────────────────────────────────────┐
│ StringBuilder Buffer │
├──────────────────────────────────────────────────────┤
│ Size ≤ 256 bytes: │
│ ┌─────────────────────────────────────┐ │
│ │ Stack Buffer (SBO) │ │
│ │ - Zero heap allocations │ │
│ │ - Cache-friendly (256 bytes) │ │
│ │ - Automatic cleanup │ │
│ └─────────────────────────────────────┘ │
│ │
│ Size > 256 bytes: │
│ ┌─────────────────────────────────────┐ │
│ │ Heap Buffer (Dynamic) │ │
│ │ - Exponential growth (< 8KB) │ │
│ │ - Conservative growth (≥ 8KB) │ │
│ │ - Managed by unique_ptr │ │
│ └─────────────────────────────────────┘ │
└──────────────────────────────────────────────────────┘

Growth Strategy:

Buffer Expansion:
┌──────────────────────────────────────────────────────┐
│ Small buffers (< 8KB): │
│ capacity_new = capacity_old × 2.0 │
│ → Aggressive growth for frequent appends │
│ │
│ Large buffers (≥ 8KB): │
│ capacity_new = capacity_old + (capacity_old / 2) │
│ → Conservative growth to limit memory overhead │
└──────────────────────────────────────────────────────┘

Definition in file StringBuilder.h.

Macro Definition Documentation

◆ NFX_STRINGBUILDER_FORCE_INLINE

#define NFX_STRINGBUILDER_FORCE_INLINE   inline

Cross-platform forced inline macro for critical hot-path methods.

Definition at line 88 of file StringBuilder.h.