PlayRho  2.0.0
An interactive physics engine & library.
playrho::StackAllocator Class Reference

#include <playrho/StackAllocator.hpp>

Classes

struct  Conf
 Stack allocator configuration data. More...
 

Public Types

using size_type = std::size_t
 Size type.
 

Public Member Functions

 StackAllocator (const Conf &config=GetDefaultConf())
 Initializing constructor.
 
 StackAllocator (const StackAllocator &copy)=delete
 Copy constructor.
 
 StackAllocator (StackAllocator &&other)=delete
 
void * Allocate (size_type size)
 
template<typename T >
T * AllocateArray (size_type size)
 Allocates and array of the given size number of elements.
 
void Free (void *p) noexcept
 Frees the given pointer.
 
auto GetAllocation () const noexcept
 Gets the total number of bytes that this object has currently allocated.
 
auto GetEntryCount () const noexcept
 
auto GetIndex () const noexcept
 
auto GetMaxAllocation () const noexcept
 Gets the max allocation.
 
auto GetMaxEntries () const noexcept
 Gets the max entries.
 
auto GetPreallocatedSize () const noexcept
 Gets the preallocated size.
 
void operator() (void *p) noexcept
 
StackAllocatoroperator= (const StackAllocator &other)=delete
 Copy assignment operator.
 
StackAllocatoroperator= (StackAllocator &&other)=delete
 

Static Public Member Functions

static constexpr Conf GetDefaultConf ()
 Gets the default configuration.
 

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.

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 function 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: