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

#include <playrho/BlockAllocator.hpp>

Classes

struct  Block
 Block. More...
 
struct  Chunk
 Chunk. More...
 

Public Types

using size_type = std::size_t
 Size type.
 

Public Member Functions

 BlockAllocator (BlockAllocator &&other)=delete
 
 BlockAllocator (const BlockAllocator &other)=delete
 
void * Allocate (size_type n)
 
template<typename T >
T * AllocateArray (size_type n)
 Allocates an array. More...
 
void Clear ()
 
void Free (void *p, size_type n)
 Frees memory. More...
 
auto GetChunkCount () const noexcept
 Gets the chunk count.
 
BlockAllocatoroperator= (BlockAllocator &&other)=delete
 
BlockAllocatoroperator= (const BlockAllocator &other)=delete
 

Static Public Member Functions

static constexpr size_type GetChunkArrayIncrement () noexcept
 Chunk array increment.
 
static constexpr size_type GetMaxBlockSize () noexcept
 Max block size (before using external allocator).
 

Static Public Attributes

static constexpr std::size_t AllocatorBlockSizes []
 Allocator block sizes array data. More...
 
static constexpr auto ChunkArrayIncrement = size_type{128}
 Chunk array increment.
 
static constexpr auto ChunkSize = size_type{16 * 1024}
 Chunk size.
 

Detailed Description

Block allocator.

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

See also
http://www.codeproject.com/useritems/Small_Block_Allocator.asp

Member Function Documentation

◆ Allocate()

void * playrho::BlockAllocator::Allocate ( size_type  n)

Allocates memory.

Allocates uninitialized storage. Uses Alloc if the size is larger than GetMaxBlockSize(). 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.

Returns
Non-null pointer if asked to make non-zero sized allocation, nullptr otherwise.
Exceptions
std::bad_allocIf unable to allocate non-zero size of memory.
See also
Alloc.

Referenced by AllocateArray().

◆ AllocateArray()

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

Allocates an array.

Exceptions
std::bad_allocIf unable to allocate non-zero elements of non-zero size.

◆ Clear()

void playrho::BlockAllocator::Clear ( )

Clears this allocator.

Note
This resets the chunk-count back to zero.

◆ Free()

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

Frees memory.

This will use free if the size is larger than GetMaxBlockSize().

Referenced by playrho::BlockDeallocator::operator()().

Member Data Documentation

◆ AllocatorBlockSizes

constexpr std::size_t playrho::BlockAllocator::AllocatorBlockSizes[]
staticconstexpr
Initial value:
=
{
16u, 32u, 64u, 96u, 128u, 160u, 192u, 224u, 256u, 320u, 384u, 448u, 512u, 640u,
}

Allocator block sizes array data.

Referenced by Allocate(), Free(), and GetMaxBlockSize().


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