nfx-stringbuilderpool 1.0.0
High-performance C++20 library for zero-allocation string building with thread-safe pooling
Loading...
Searching...
No Matches
StringBuilderPool.h File Reference

String pooling implementation for high-performance string building. More...

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

Go to the source code of this file.

Classes

class  nfx::string::DynamicStringBuffer
 High-performance dynamic string buffer with efficient memory management. More...
 
class  nfx::string::StringBuilder
 High-performance string builder with fluent interface and efficient memory management. More...
 
class  nfx::string::StringBuilder::Enumerator
 Forward-only iterator for character-by-character enumeration of StringBuilder content. More...
 
class  nfx::string::StringBuilderLease
 RAII lease wrapper for pooled StringBuilder buffers with automatic resource management. More...
 
class  nfx::string::StringBuilderPool
 Thread-safe memory pool for high-performance StringBuilder instances with optimized allocation strategy. More...
 
struct  nfx::string::StringBuilderPool::PoolStatistics
 Pool performance statistics for external access. More...
 

Detailed Description

String pooling implementation for high-performance string building.

Thread-safe shared pool with RAII lease management and statistics

StringBuilderPool High-Level Architecture:

StringBuilderPool Public API Structure:
┌─────────────────────────────────────────────────────────────┐
│ StringBuilderPool (Static Interface) │
├─────────────────────────────────────────────────────────────┤
│ lease() → StringBuilderLease │ ← Primary factory method
│ ↓ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ StringBuilderLease (RAII) │ │ ← Automatic cleanup
│ │ ┌─────────────────────────────────────────────┐ │ │
│ │ │ create() → StringBuilder │ │ │ ← Fluent interface
│ │ │ buffer() → DynamicStringBuffer │ │ │ ← Direct access
│ │ │ toString() → std::string │ │ │ ← Conversion
│ │ └─────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ StringBuilder: Fluent string building interface │ ← Stream operators
│ DynamicStringBuffer: High-performance buffer (SBO) │ ← Zero-copy operations
└─────────────────────────────────────────────────────────────┘

Typical Usage Pattern:

StringBuilderPool Usage Flow:
┌─────────────────────────────────────────────────────────────┐
│ User Code Example │
├─────────────────────────────────────────────────────────────┤
// 1. Acquire lease (automatic pooling) │
auto lease = StringBuilderPool::lease(); │
│ ↓ │
// 2. Create builder for fluent operations │
auto builder = lease.create(); │
│ ↓ │
// 3. Build string with zero allocations │
│ builder << "Hello" << ", " << "World" << "!"; │
│ builder.append(" Additional text"); │
│ ↓ │
// 4. Extract result │
│ std::string result = lease.toString(); │
│ ↓ │
// 5. Automatic cleanup (lease destructor) │
// Buffer returned to pool for reuse │
└─────────────────────────────────────────────────────────────┘

Definition in file StringBuilderPool.h.