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

Stack memory manager class. More...

#include <allocator_stack.h>

Public Member Functions

 StackMemoryManager ()
 
 StackMemoryManager (const StackMemoryManager &)=delete
 
 StackMemoryManager (StackMemoryManager &&)=delete
 
 ~StackMemoryManager () noexcept
 
StackMemoryManageroperator= (const StackMemoryManager &)=delete
 
StackMemoryManageroperator= (StackMemoryManager &&)=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
 Stack buffer. More...
 
size_t capacity () const noexcept
 Stack capacity. More...
 
size_t size () const noexcept
 Stack allocated size. More...
 
size_t max_size () const noexcept
 Maximum memory block size, that could be allocated by the 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...
 

Detailed Description

template<size_t N>
class CppCommon::StackMemoryManager< N >

Stack memory manager class.

Stack memory manager uses current stack buffer of the given size as a source of memory during the allocation.

When a new block of memory allocated then the stack free size is checked and the free offset is moved. If there is no enough space std::bad_alloc will be thrown or null is returned (depends on parameter).

Deallocate method does nothing. When the allocation/deallocation phase is finished then the free stack offset could be reset with a corresponding method.

Not thread-safe.

Definition at line 32 of file allocator_stack.h.

Constructor & Destructor Documentation

◆ StackMemoryManager() [1/3]

template<size_t N>
CppCommon::StackMemoryManager< N >::StackMemoryManager
inline

Definition at line 12 of file allocator_stack.inl.

◆ StackMemoryManager() [2/3]

template<size_t N>
CppCommon::StackMemoryManager< N >::StackMemoryManager ( const StackMemoryManager< N > &  )
delete

◆ StackMemoryManager() [3/3]

template<size_t N>
CppCommon::StackMemoryManager< N >::StackMemoryManager ( StackMemoryManager< N > &&  )
delete

◆ ~StackMemoryManager()

template<size_t N>
CppCommon::StackMemoryManager< N >::~StackMemoryManager ( )
inlinenoexcept

Definition at line 38 of file allocator_stack.h.

Member Function Documentation

◆ allocated()

template<size_t N>
size_t CppCommon::StackMemoryManager< N >::allocated ( ) const
inlinenoexcept

Allocated memory in bytes.

Definition at line 44 of file allocator_stack.h.

◆ allocations()

template<size_t N>
size_t CppCommon::StackMemoryManager< N >::allocations ( ) const
inlinenoexcept

Count of active memory allocations.

Definition at line 46 of file allocator_stack.h.

◆ buffer()

template<size_t N>
const uint8_t* CppCommon::StackMemoryManager< N >::buffer ( ) const
inlinenoexcept

Stack buffer.

Definition at line 49 of file allocator_stack.h.

◆ capacity()

template<size_t N>
size_t CppCommon::StackMemoryManager< N >::capacity ( ) const
inlinenoexcept

Stack capacity.

Definition at line 51 of file allocator_stack.h.

◆ free()

template<size_t N>
void CppCommon::StackMemoryManager< N >::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 48 of file allocator_stack.inl.

◆ malloc()

template<size_t N>
void * CppCommon::StackMemoryManager< N >::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 21 of file allocator_stack.inl.

◆ max_size()

template<size_t N>
size_t CppCommon::StackMemoryManager< N >::max_size ( ) const
inlinenoexcept

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

Definition at line 56 of file allocator_stack.h.

◆ operator=() [1/2]

template<size_t N>
StackMemoryManager& CppCommon::StackMemoryManager< N >::operator= ( const StackMemoryManager< N > &  )
delete

◆ operator=() [2/2]

template<size_t N>
StackMemoryManager& CppCommon::StackMemoryManager< N >::operator= ( StackMemoryManager< N > &&  )
delete

◆ reset()

template<size_t N>
void CppCommon::StackMemoryManager< N >::reset
inline

Reset the memory manager.

Definition at line 61 of file allocator_stack.inl.

◆ size()

template<size_t N>
size_t CppCommon::StackMemoryManager< N >::size ( ) const
inlinenoexcept

Stack allocated size.

Definition at line 53 of file allocator_stack.h.


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