|
nfx-stringbuilder 0.1.1
High-performance C++20 library for zero-allocation string building with thread-safe pooling
|
Thread-safe memory pool for high-performance StringBuilder instances with optimized allocation strategy. More...
#include <nfx/string/StringBuilder.h>
Classes | |
| struct | PoolStatistics |
| Pool performance statistics for external access. More... | |
Static Public Member Functions | |
| static StringBuilderLease | lease () |
| Creates a new StringBuilder lease with an optimally sourced memory buffer. | |
| static StringBuilderLease | lease (size_t capacityHint) |
| Creates a new StringBuilder lease with pre-allocated capacity hint. | |
| static PoolStatistics | stats () noexcept |
| Gets current pool statistics. | |
| static void | resetStats () noexcept |
| Resets pool statistics. | |
| static size_t | clear () |
| Clears all buffers from the pool and returns the count of cleared buffers. | |
| static size_t | size () noexcept |
| Gets current number of buffers stored in the pool. | |
Thread-safe memory pool for high-performance StringBuilder instances with optimized allocation strategy.
Implements a three-tier pooling system for DynamicStringBuffer instances to minimize allocation overhead in high-frequency string building scenarios. Features thread-local caching, shared cross-thread pooling, and comprehensive statistics tracking. Designed as a singleton with static factory methods for global access.
Definition at line 867 of file StringBuilder.h.
|
static |
Clears all buffers from the pool and returns the count of cleared buffers.


|
staticnodiscard |
Creates a new StringBuilder lease with an optimally sourced memory buffer.
This is the primary factory method for obtaining StringBuilder instances. The buffer is sourced using a three-tier optimization strategy:
The returned lease automatically returns the buffer to the pool when destroyed, ensuring optimal memory reuse and preventing leaks.
This method is thread-safe and optimized for high-frequency usage patterns. Buffers are automatically cleared before reuse and size-limited to prevent bloat.
|
staticnodiscard |
Creates a new StringBuilder lease with pre-allocated capacity hint.
| capacityHint | Minimum desired buffer capacity in bytes |
Pre-allocates buffer capacity to avoid reallocations during string construction. The buffer is sourced using the same three-tier optimization strategy as lease(), but with an additional reserve() call to ensure sufficient capacity.
Use this overload when the approximate final size is known in advance to minimize memory allocations and improve performance.
Example:
This method is thread-safe and optimized for high-frequency usage patterns. Buffers are automatically cleared before reuse and size-limited to prevent bloat.
|
staticnoexcept |
Gets current number of buffers stored in the pool.


|
staticnoexcept |
Gets current pool statistics.