Box2D  3.0.0
A Real-Time-Oriented 2-D Physics Engine
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
box2d::StackAllocator Class Reference

Stack allocator. More...

#include <StackAllocator.hpp>

Classes

struct  Configuration
 

Public Types

using size_type = size_t
 

Public Member Functions

 StackAllocator (Configuration config=GetDefaultConfiguration()) noexcept
 
 ~StackAllocator () noexcept
 
 StackAllocator (const StackAllocator &copy)=delete
 
void * Allocate (size_type size) noexcept
 Allocates an aligned block of memory of the given size. More...
 
void Free (void *p) noexcept
 
template<typename T >
T * AllocateArray (size_type size) noexcept
 
void operator() (void *p) noexcept
 Functional operator for freeing memory allocated by this object. More...
 
auto GetMaxAllocation () const noexcept
 
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. More...
 
auto GetPreallocatedSize () const noexcept
 
auto GetMaxEntries () const noexcept
 

Static Public Member Functions

static constexpr Configuration GetDefaultConfiguration ()
 

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 concept.
This data structure is 64-bytes large (on at least one 64-bit platform).

Member Typedef Documentation

◆ size_type

Constructor & Destructor Documentation

◆ StackAllocator() [1/2]

StackAllocator::StackAllocator ( Configuration  config = GetDefaultConfiguration())
noexcept

◆ ~StackAllocator()

StackAllocator::~StackAllocator ( )
noexcept

◆ StackAllocator() [2/2]

box2d::StackAllocator::StackAllocator ( const StackAllocator copy)
delete

Member Function Documentation

◆ Allocate()

void * StackAllocator::Allocate ( size_type  size)
noexcept

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.

◆ AllocateArray()

template<typename T >
T* box2d::StackAllocator::AllocateArray ( size_type  size)
inlinenoexcept

◆ Free()

void StackAllocator::Free ( void *  p)
noexcept

◆ GetAllocation()

auto box2d::StackAllocator::GetAllocation ( ) const
inlinenoexcept

Gets the total number of bytes that this object has currently allocated.

◆ GetDefaultConfiguration()

static constexpr Configuration box2d::StackAllocator::GetDefaultConfiguration ( )
inlinestatic

◆ GetEntryCount()

auto box2d::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 box2d::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.

◆ GetMaxAllocation()

auto box2d::StackAllocator::GetMaxAllocation ( ) const
inlinenoexcept

◆ GetMaxEntries()

auto box2d::StackAllocator::GetMaxEntries ( ) const
inlinenoexcept

◆ GetPreallocatedSize()

auto box2d::StackAllocator::GetPreallocatedSize ( ) const
inlinenoexcept

◆ operator()()

void box2d::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: