OpenXLSX 1.12.1
Modern C++ Excel Library (Fork of OpenXLSX by Kenneth Troldal Balslev)
Loading...
Searching...
No Matches
OpenXLSX::XLStringArena Class Reference

String memory pool (Arena Allocator) with block recycling. More...

#include <XLStringArena.hpp>

Public Member Functions

 XLStringArena (size_t blockSize=4 *1024 *1024)
 XLStringArena (const XLStringArena &)=delete
XLStringArena & operator= (const XLStringArena &)=delete
 XLStringArena (XLStringArena &&) noexcept=default
XLStringArena & operator= (XLStringArena &&) noexcept=default
std::string_view store (std::string_view str)
 Store a string in the arena and return a non-owning view.
void clear () noexcept
 Recycle all blocks for reuse without freeing heap memory.
void reset () noexcept
 Release all memory (active + free blocks). Use at shutdown.
size_t capacity () const noexcept
 Total bytes allocated (active blocks only).
size_t used () const noexcept
 Bytes used in the current active block.

Detailed Description

String memory pool (Arena Allocator) with block recycling.

Adheres to C++ Core Guidelines:

  1. RAII resource management (no naked new/delete)
  2. No copy construction/assignment to prevent dangling pointers (Rule of 5)
  3. Provides zero-copy access via std::string_view
  4. clear() recycles memory blocks instead of freeing them, eliminating malloc/free churn when the arena is reused across save cycles.

Constructor & Destructor Documentation

◆ XLStringArena() [1/3]

OpenXLSX::XLStringArena::XLStringArena ( size_t blockSize = 4 * 1024 * 1024)
inlineexplicit

◆ XLStringArena() [2/3]

OpenXLSX::XLStringArena::XLStringArena ( const XLStringArena & )
delete

◆ XLStringArena() [3/3]

OpenXLSX::XLStringArena::XLStringArena ( XLStringArena && )
defaultnoexcept

Member Function Documentation

◆ capacity()

size_t OpenXLSX::XLStringArena::capacity ( ) const
inlinenodiscardnoexcept

Total bytes allocated (active blocks only).

◆ clear()

void OpenXLSX::XLStringArena::clear ( )
inlinenoexcept

Recycle all blocks for reuse without freeing heap memory.

Moves active blocks to the free list so the next store() calls can reuse them without malloc. Call reset() at shutdown to actually release all memory.

◆ operator=() [1/2]

XLStringArena & OpenXLSX::XLStringArena::operator= ( const XLStringArena & )
delete

◆ operator=() [2/2]

XLStringArena & OpenXLSX::XLStringArena::operator= ( XLStringArena && )
defaultnoexcept

◆ reset()

void OpenXLSX::XLStringArena::reset ( )
inlinenoexcept

Release all memory (active + free blocks). Use at shutdown.

◆ store()

std::string_view OpenXLSX::XLStringArena::store ( std::string_view str)
inlinenodiscard

Store a string in the arena and return a non-owning view.

Parameters
strThe string view to store (null-terminated in the arena).
Returns
std::string_view pointing into the arena's storage.

◆ used()

size_t OpenXLSX::XLStringArena::used ( ) const
inlinenodiscardnoexcept

Bytes used in the current active block.


The documentation for this class was generated from the following file: