#include <BlockAllocator.hpp>

Classes

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

Public Types

using size_type = std::size_t
 Size type. More...
 

Public Member Functions

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

Static Public Member Functions

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

Static Public Attributes

static const PLAYRHO_CONSTEXPR auto ChunkSize = size_type{16 * 1024}
 Chunk size. More...
 

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

Definition at line 40 of file BlockAllocator.hpp.

Member Typedef Documentation

◆ size_type

Size type.

Definition at line 45 of file BlockAllocator.hpp.

Constructor & Destructor Documentation

◆ BlockAllocator() [1/3]

playrho::BlockAllocator::BlockAllocator ( )

Definition at line 105 of file BlockAllocator.cpp.

◆ BlockAllocator() [2/3]

playrho::BlockAllocator::BlockAllocator ( const BlockAllocator other)
delete

◆ BlockAllocator() [3/3]

playrho::BlockAllocator::BlockAllocator ( BlockAllocator &&  other)
delete

◆ ~BlockAllocator()

playrho::BlockAllocator::~BlockAllocator ( )
noexcept

Definition at line 114 of file BlockAllocator.cpp.

Member Function Documentation

◆ GetMaxBlockSize()

static PLAYRHO_CONSTEXPR size_type playrho::BlockAllocator::GetMaxBlockSize ( )
inlinestaticnoexcept

Max block size (before using external allocator).

Definition at line 51 of file BlockAllocator.hpp.

◆ GetChunkArrayIncrement()

static PLAYRHO_CONSTEXPR size_type playrho::BlockAllocator::GetChunkArrayIncrement ( )
inlinestaticnoexcept

Chunk array increment.

Definition at line 57 of file BlockAllocator.hpp.

◆ operator=() [1/2]

BlockAllocator& playrho::BlockAllocator::operator= ( const BlockAllocator other)
delete

◆ operator=() [2/2]

BlockAllocator& playrho::BlockAllocator::operator= ( BlockAllocator &&  other)
delete

◆ 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.

See also
Alloc.

Definition at line 123 of file BlockAllocator.cpp.

◆ AllocateArray()

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

Allocates an array.

Definition at line 85 of file BlockAllocator.hpp.

◆ Free()

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

Frees memory.

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

Definition at line 178 of file BlockAllocator.cpp.

◆ Clear()

void playrho::BlockAllocator::Clear ( )

Clears this allocator.

Note
This resets the chunk-count back to zero.

Definition at line 218 of file BlockAllocator.cpp.

◆ GetChunkCount()

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

Gets the chunk count.

Definition at line 99 of file BlockAllocator.hpp.

Member Data Documentation

◆ ChunkSize

const PLAYRHO_CONSTEXPR auto playrho::BlockAllocator::ChunkSize = size_type{16 * 1024}
static

Chunk size.

Definition at line 48 of file BlockAllocator.hpp.


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