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

Block allocator. More...

#include <BlockAllocator.hpp>

Classes

struct  Block
 
struct  Chunk
 

Public Types

using size_type = size_t
 

Public Member Functions

 BlockAllocator ()
 
 ~BlockAllocator () noexcept
 
void * Allocate (size_type n)
 Allocates memory. More...
 
template<typename T >
T * AllocateArray (size_type n)
 
void Free (void *p, size_type n)
 Free memory. More...
 
void Clear ()
 Clears this allocator. More...
 
auto GetChunkCount () const noexcept
 

Static Public Attributes

static constexpr auto ChunkSize = size_type{16 * 1024}
 Chunk size. More...
 
static constexpr auto MaxBlockSize = size_type{640}
 Max block size (before using external allocator). More...
 
static constexpr auto BlockSizes = size_type{14}
 
static constexpr auto ChunkArrayIncrement = size_type{128}
 

Detailed Description

Block allocator.

This is a small object allocator used for allocating small objects that persist for more than one time step.

Note
This data structure is 136-bytes large (on at least one 64-bit platform).
See also
http://www.codeproject.com/useritems/Small_Block_Allocator.asp

Member Typedef Documentation

◆ size_type

Constructor & Destructor Documentation

◆ BlockAllocator()

BlockAllocator::BlockAllocator ( )

◆ ~BlockAllocator()

BlockAllocator::~BlockAllocator ( )
noexcept

Member Function Documentation

◆ Allocate()

void * BlockAllocator::Allocate ( size_type  n)

Allocates memory.

Allocates uninitialized storage. Uses alloc if the size is larger than MaxBlockSize. Otherwise looks for an appropriately sized block from the free list. Failing that, alloc is used to grow the free list from which memory is returned.

See also
alloc.

◆ AllocateArray()

template<typename T >
T* box2d::BlockAllocator::AllocateArray ( size_type  n)
inline

◆ Clear()

void BlockAllocator::Clear ( )

Clears this allocator.

Note
This resets the chunk-count back to zero.

◆ Free()

void BlockAllocator::Free ( void *  p,
size_type  n 
)

Free memory.

This will use free if the size is larger than MaxBlockSize.

◆ GetChunkCount()

auto box2d::BlockAllocator::GetChunkCount ( ) const
inlinenoexcept

Member Data Documentation

◆ BlockSizes

constexpr auto box2d::BlockAllocator::BlockSizes = size_type{14}
static

◆ ChunkArrayIncrement

constexpr auto box2d::BlockAllocator::ChunkArrayIncrement = size_type{128}
static

◆ ChunkSize

constexpr auto box2d::BlockAllocator::ChunkSize = size_type{16 * 1024}
static

Chunk size.

◆ MaxBlockSize

constexpr auto box2d::BlockAllocator::MaxBlockSize = size_type{640}
static

Max block size (before using external allocator).


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