PlayRho  1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
playrho::StackAllocator Class Reference

Stack allocator. More...

#include <StackAllocator.hpp>

Collaboration diagram for playrho::StackAllocator:
[legend]

Classes

struct  AllocationRecord
 Allocation record. More...
 
struct  Conf
 Stack allocator configuration data. More...
 

Public Types

using size_type = std::size_t
 Size type.
 

Public Member Functions

 StackAllocator (Conf config=GetDefaultConf())
 Initializing constructor.
 
 StackAllocator (const StackAllocator &copy)=delete
 Copy constructor.
 
 StackAllocator (StackAllocator &&other)=delete
 
StackAllocatoroperator= (const StackAllocator &other)=delete
 Copy assignment operator.
 
StackAllocatoroperator= (StackAllocator &&other)=delete
 
void * Allocate (size_type size)
 Allocates an aligned block of memory of the given size. More...
 
void Free (void *p) noexcept
 Frees the given pointer.
 
template<typename T >
T * AllocateArray (size_type size)
 Allocates and array of the given size number of elements.
 
void operator() (void *p) noexcept
 Functional operator for freeing memory allocated by this object. More...
 
auto GetMaxAllocation () const noexcept
 Gets the max allocation.
 
auto GetEntryCount () const noexcept
 Gets the current allocation record entry usage count. More...
 
auto GetIndex () const noexcept
 Gets the current index location. More...
 
auto GetAllocation () const noexcept
 Gets the total number of bytes that this object has currently allocated.
 
auto GetPreallocatedSize () const noexcept
 Gets the preallocated size.
 
auto GetMaxEntries () const noexcept
 Gets the max entries.
 

Static Public Member Functions

static constexpr Conf GetDefaultConf ()
 Gets the default configuration.
 

Private Attributes

char *const m_data
 Data.
 
AllocationRecord *const m_entries
 Entries.
 
size_type const m_size
 Size.
 
size_type const m_max_entries
 Max entries.
 
size_type m_index = 0
 Index.
 
size_type m_allocation = 0
 Allocation.
 
size_type m_maxAllocation = 0
 Max allocation.
 
size_type m_entryCount = 0
 Entry count.
 

Detailed Description

Stack allocator.

This is a stack allocator used for fast per step allocations. You must nest allocate/free pairs. The code will assert if you try to interleave multiple allocate/free pairs.

Note
This class satisfies the C++11 std::unique_ptr() Deleter requirement.
This data structure is 64-bytes large (on at least one 64-bit platform).

Member Function Documentation

◆ Allocate()

void * StackAllocator::Allocate ( size_type  size)

Allocates an aligned block of memory of the given size.

Returns
Pointer to memory if the allocator has allocation records left, nullptr otherwise.
See also
GetEntryCount.

Referenced by AllocateArray().

◆ GetEntryCount()

auto playrho::StackAllocator::GetEntryCount ( ) const
inlinenoexcept

Gets the current allocation record entry usage count.

Returns
Value between 0 and the maximum number of entries possible for this allocator.
See also
GetMaxEntries.

◆ GetIndex()

auto playrho::StackAllocator::GetIndex ( ) const
inlinenoexcept

Gets the current index location.

This represents the number of bytes used (of the storage allocated at construction time by this object). Storage remaining is calculated by subtracting this value from StackSize.

Returns
Value between 0 and StackSize.

◆ operator()()

void playrho::StackAllocator::operator() ( void *  p)
inlinenoexcept

Functional operator for freeing memory allocated by this object.

This method frees memory (like called Free) and allows this object to be used as deleter to std::unique_ptr.


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