CppCommon  1.0.4.1
C++ Common Library
Classes | Public Member Functions | List of all members
CppCommon::ArenaMemoryManager< TAuxMemoryManager > Class Template Reference

Arena memory manager class. More...

#include <allocator_arena.h>

Public Member Functions

 ArenaMemoryManager (TAuxMemoryManager &auxiliary)
 Initialize arena memory manager with an auxiliary memory manager. More...
 
 ArenaMemoryManager (TAuxMemoryManager &auxiliary, size_t capacity)
 Initialize arena memory manager with an auxiliary memory manager and a given page capacity. More...
 
 ArenaMemoryManager (TAuxMemoryManager &auxiliary, void *buffer, size_t capacity)
 Initialize arena memory manager with an auxiliary memory manager and a given buffer. More...
 
 ArenaMemoryManager (const ArenaMemoryManager &)=delete
 
 ArenaMemoryManager (ArenaMemoryManager &&)=delete
 
 ~ArenaMemoryManager ()
 
ArenaMemoryManageroperator= (const ArenaMemoryManager &)=delete
 
ArenaMemoryManageroperator= (ArenaMemoryManager &&)=delete
 
size_t allocated () const noexcept
 Allocated memory in bytes. More...
 
size_t allocations () const noexcept
 Count of active memory allocations. More...
 
const uint8_t * buffer () const noexcept
 Arena buffer. More...
 
size_t capacity () const noexcept
 Arena capacity. More...
 
size_t size () const noexcept
 Arena allocated size. More...
 
size_t max_size () const noexcept
 Maximum memory block size, that could be allocated by the memory manager. More...
 
TAuxMemoryManager & auxiliary () noexcept
 Auxiliary memory manager. More...
 
void * malloc (size_t size, size_t alignment=alignof(std::max_align_t))
 Allocate a new memory block of the given size. More...
 
void free (void *ptr, size_t size)
 Free the previously allocated memory block. More...
 
void reset ()
 Reset the memory manager. More...
 
void reset (size_t capacity)
 Reset the memory manager with a given page capacity. More...
 
void reset (void *buffer, size_t capacity)
 Reset the memory manager with a given buffer. More...
 
void clear ()
 Clear arena memory allocator. More...
 

Detailed Description

template<class TAuxMemoryManager = DefaultMemoryManager>
class CppCommon::ArenaMemoryManager< TAuxMemoryManager >

Arena memory manager class.

Arena memory manager uses pre-allocated memory buffer (arena) as a first source of memory during the allocation. If arena buffer has insufficient space to allocate the required block then an auxiliary memory manager will be used.

Arena memory manager is suitable for multiple allocations during long operations with a single reset at the end (e.g. HTTP request processing).

Not thread-safe.

Examples
memory_arena.cpp.

Definition at line 29 of file allocator_arena.h.

Constructor & Destructor Documentation

◆ ArenaMemoryManager() [1/5]

template<class TAuxMemoryManager = DefaultMemoryManager>
CppCommon::ArenaMemoryManager< TAuxMemoryManager >::ArenaMemoryManager ( TAuxMemoryManager &  auxiliary)
inlineexplicit

Initialize arena memory manager with an auxiliary memory manager.

Arena page capacity will be 65536.

Parameters
auxiliary- Auxiliary memory manager

Definition at line 38 of file allocator_arena.h.

◆ ArenaMemoryManager() [2/5]

template<class TAuxMemoryManager >
CppCommon::ArenaMemoryManager< TAuxMemoryManager >::ArenaMemoryManager ( TAuxMemoryManager &  auxiliary,
size_t  capacity 
)
inlineexplicit

Initialize arena memory manager with an auxiliary memory manager and a given page capacity.

Parameters
auxiliary- Auxiliary memory manager
capacity- Arena page capacity in bytes

Definition at line 12 of file allocator_arena.inl.

◆ ArenaMemoryManager() [3/5]

template<class TAuxMemoryManager >
CppCommon::ArenaMemoryManager< TAuxMemoryManager >::ArenaMemoryManager ( TAuxMemoryManager &  auxiliary,
void *  buffer,
size_t  capacity 
)
inlineexplicit

Initialize arena memory manager with an auxiliary memory manager and a given buffer.

Parameters
auxiliary- Auxiliary memory manager
buffer- Arena buffer
capacity- Arena buffer capacity

Definition at line 27 of file allocator_arena.inl.

◆ ArenaMemoryManager() [4/5]

template<class TAuxMemoryManager = DefaultMemoryManager>
CppCommon::ArenaMemoryManager< TAuxMemoryManager >::ArenaMemoryManager ( const ArenaMemoryManager< TAuxMemoryManager > &  )
delete

◆ ArenaMemoryManager() [5/5]

template<class TAuxMemoryManager = DefaultMemoryManager>
CppCommon::ArenaMemoryManager< TAuxMemoryManager >::ArenaMemoryManager ( ArenaMemoryManager< TAuxMemoryManager > &&  )
delete

◆ ~ArenaMemoryManager()

template<class TAuxMemoryManager = DefaultMemoryManager>
CppCommon::ArenaMemoryManager< TAuxMemoryManager >::~ArenaMemoryManager ( )
inline

Definition at line 54 of file allocator_arena.h.

Member Function Documentation

◆ allocated()

template<class TAuxMemoryManager = DefaultMemoryManager>
size_t CppCommon::ArenaMemoryManager< TAuxMemoryManager >::allocated ( ) const
inlinenoexcept

Allocated memory in bytes.

Definition at line 60 of file allocator_arena.h.

◆ allocations()

template<class TAuxMemoryManager = DefaultMemoryManager>
size_t CppCommon::ArenaMemoryManager< TAuxMemoryManager >::allocations ( ) const
inlinenoexcept

Count of active memory allocations.

Definition at line 62 of file allocator_arena.h.

◆ auxiliary()

template<class TAuxMemoryManager = DefaultMemoryManager>
TAuxMemoryManager& CppCommon::ArenaMemoryManager< TAuxMemoryManager >::auxiliary ( )
inlinenoexcept

Auxiliary memory manager.

Definition at line 75 of file allocator_arena.h.

◆ buffer()

template<class TAuxMemoryManager = DefaultMemoryManager>
const uint8_t* CppCommon::ArenaMemoryManager< TAuxMemoryManager >::buffer ( ) const
inlinenoexcept

Arena buffer.

Definition at line 65 of file allocator_arena.h.

◆ capacity()

template<class TAuxMemoryManager = DefaultMemoryManager>
size_t CppCommon::ArenaMemoryManager< TAuxMemoryManager >::capacity ( ) const
inlinenoexcept

Arena capacity.

Definition at line 67 of file allocator_arena.h.

◆ clear()

template<class TAuxMemoryManager >
void CppCommon::ArenaMemoryManager< TAuxMemoryManager >::clear
inline

Clear arena memory allocator.

Definition at line 217 of file allocator_arena.inl.

◆ free()

template<class TAuxMemoryManager >
void CppCommon::ArenaMemoryManager< TAuxMemoryManager >::free ( void *  ptr,
size_t  size 
)
inline

Free the previously allocated memory block.

Parameters
ptr- Pointer to the memory block
size- Block size

Definition at line 139 of file allocator_arena.inl.

◆ malloc()

template<class TAuxMemoryManager >
void * CppCommon::ArenaMemoryManager< TAuxMemoryManager >::malloc ( size_t  size,
size_t  alignment = alignof(std::max_align_t) 
)
inline

Allocate a new memory block of the given size.

Parameters
size- Block size
alignment- Block alignment (default is alignof(std::max_align_t))
Returns
A pointer to the allocated memory block or nullptr in case of allocation failed

Definition at line 42 of file allocator_arena.inl.

◆ max_size()

template<class TAuxMemoryManager = DefaultMemoryManager>
size_t CppCommon::ArenaMemoryManager< TAuxMemoryManager >::max_size ( ) const
inlinenoexcept

Maximum memory block size, that could be allocated by the memory manager.

Definition at line 72 of file allocator_arena.h.

◆ operator=() [1/2]

template<class TAuxMemoryManager = DefaultMemoryManager>
ArenaMemoryManager& CppCommon::ArenaMemoryManager< TAuxMemoryManager >::operator= ( ArenaMemoryManager< TAuxMemoryManager > &&  )
delete

◆ operator=() [2/2]

template<class TAuxMemoryManager = DefaultMemoryManager>
ArenaMemoryManager& CppCommon::ArenaMemoryManager< TAuxMemoryManager >::operator= ( const ArenaMemoryManager< TAuxMemoryManager > &  )
delete

◆ reset() [1/3]

template<class TAuxMemoryManager >
void CppCommon::ArenaMemoryManager< TAuxMemoryManager >::reset
inline

Reset the memory manager.

Definition at line 162 of file allocator_arena.inl.

◆ reset() [2/3]

template<class TAuxMemoryManager >
void CppCommon::ArenaMemoryManager< TAuxMemoryManager >::reset ( size_t  capacity)
inline

Reset the memory manager with a given page capacity.

Parameters
capacity- Arena page capacity in bytes

Definition at line 175 of file allocator_arena.inl.

◆ reset() [3/3]

template<class TAuxMemoryManager >
void CppCommon::ArenaMemoryManager< TAuxMemoryManager >::reset ( void *  buffer,
size_t  capacity 
)
inline

Reset the memory manager with a given buffer.

Parameters
buffer- Arena buffer
capacity- Arena buffer capacity

Definition at line 195 of file allocator_arena.inl.

◆ size()

template<class TAuxMemoryManager = DefaultMemoryManager>
size_t CppCommon::ArenaMemoryManager< TAuxMemoryManager >::size ( ) const
inlinenoexcept

Arena allocated size.

Definition at line 69 of file allocator_arena.h.


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