Bond 0.9
C++ Bond Runtime Library API Documentation
Loading...
Searching...
No Matches
Bond::Allocator Class Referenceabstract

Abstract base class defining the interface through which all components of Bond perform memory and object allocations. More...

#include <bond/systems/allocator.h>

Inheritance diagram for Bond::Allocator:
Bond::DefaultAllocator

Classes

struct  AlignedDeallocator
 A custom unique_ptr deleter that deallocates aligned memory by calling Allocator::FreeAligned, rather than the delete operator. The memory is only freed; no object destruction is performed. More...
 
class  AlignedHandle
 An owning memory handle that derives from unique_ptr that deallocates memory using an AlignedDeallocator rather than std::default_delete when it goes out of scope. More...
 
struct  AlignedObjectDeallocator
 A custom unique_ptr deleter that destroys an aligned object by calling its destructor then freeing its memory by calling Allocator::FreeAligned rather than the delete operator. More...
 
class  AlignedObjectHandle
 An owning object handle that derives from unique_ptr that destroys an aligned object using an AlignedObjectDeallocator rather than std::default_delete when it goes out of scope. More...
 
struct  Deallocator
 A custom unique_ptr deleter that deallocates memory by calling Allocator::Free rather than the delete operator. The memory is only freed; no object destruction is performed. More...
 
class  Handle
 An owning memory handle that derives from unique_ptr that deallocates memory using a Deallocator rather than std::default_delete when it goes out of scope. More...
 
struct  ObjectDeallocator
 A custom unique_ptr deleter that destroys an object by calling its destructor then freeing its memory by calling Allocator::Free rather than the delete operator. More...
 
class  ObjectHandle
 An owning object handle that derives from unique_ptr that destroys an object using an ObjectDeallocator rather than std::default_delete when it goes out of scope. More...
 

Public Member Functions

virtual ~Allocator ()
 
virtual void * Allocate (size_t size)=0
 Allocates and returns a pointer to a block of uninitialized memory of the given size. More...
 
virtual void * AllocateAligned (size_t size, size_t align)=0
 Allocates and returns a pointer to a block of uninitialized memory with the given size and alignment. More...
 
virtual void Free (void *buffer)=0
 Frees the memory pointed to by the given pointer. The memory must have been allocated by this allocator's Allocate method. More...
 
virtual void FreeAligned (void *buffer)=0
 Frees the aligned memory pointed to by the given pointer. The memory must have been allocated by this allocator's Allocate method. More...
 
void Free (const void *buffer)
 Calls the non-const form of Free after casting away the constness of the given pointer. More...
 
void FreeAligned (const void *buffer)
 Calls the non-const form of FreeAligned after casting away the constness of the given pointer. More...
 
template<typename T >
T * Alloc ()
 Allocates and returns a pointer to a block of uninitialized memory large enough to accomodate an object of type T. More...
 
template<typename T >
T * Alloc (size_t numElements)
 Allocates and returns a pointer to a block of uninitialized memory large enough to accomodate an array of objects of type T. More...
 
template<typename T >
Handle< T > AllocOwned ()
 Allocates and returns an owning handle to a block of uninitialized memory large enough to accomodate an object of type T. More...
 
template<typename T >
Handle< T > AllocOwned (size_t numElements)
 Allocates and returns an owning handle to a block of uninitialized memory large enough to accomodate an array of objects of type T. More...
 
template<typename T >
T * AllocAligned (size_t align)
 Allocates and returns a pointer to a block of uninitialized aligned memory large enough to accomodate an object of type T. More...
 
template<typename T >
T * AllocAligned (size_t numElements, size_t align)
 Allocates and returns a pointer to a block of uninitialized aligned memory large enough to accomodate an array of objects of type T. More...
 
template<typename T >
AlignedHandle< T > AllocOwnedAligned (size_t align)
 Allocates and returns an owning handle to a block of uninitialized aligned memory large enough to accomodate an object of type T. More...
 
template<typename T >
AlignedHandle< T > AllocOwnedAligned (size_t numElements, size_t align)
 Allocates and returns an owning handle to a block of uninitialized aligned memory large enough to accomodate an array of objects of type T. More...
 
template<typename T , typename... Args>
T * AllocObject (Args &&... args)
 Allocates, constructs and returns a pointer to an instance of type T. More...
 
template<typename T , typename... Args>
ObjectHandle< T > AllocOwnedObject (Args &&... args)
 Allocates, constructs and returns an owning handle to an instance of type T. More...
 
template<typename T , typename... Args>
T * AllocAlignedObject (size_t align, Args &&... args)
 Allocates, constructs and returns a pointer to an aligned instance of type T. More...
 
template<typename T , typename... Args>
AlignedObjectHandle< T > AllocOwnedAlignedObject (size_t align, Args &&... args)
 Allocates, constructs and returns an owning handle to an aligned instance of type T. More...
 

Detailed Description

Abstract base class defining the interface through which all components of Bond perform memory and object allocations.

The Allocator provides a variety of methods to allocate memory and to allocate and construct objects, all of which can either be unaligned or aligned. Additionally, it provides methods to destroy objects and free memory, as well as handles that derive from the standard C++ unique_ptr to ensure that resources are released reliably.

Concrete derived classes need to provide implementations for the Allocator::Allocate, Allocator::AllocateAligned, Allocator::Free and Allocator::FreeAligned methods. All other functionality provided by this class is built on top of those four methods.

Constructor & Destructor Documentation

◆ ~Allocator()

virtual Bond::Allocator::~Allocator ( )
inlinevirtual

Member Function Documentation

◆ Alloc() [1/2]

template<typename T >
T * Bond::Allocator::Alloc ( )
inline

Allocates and returns a pointer to a block of uninitialized memory large enough to accomodate an object of type T.

◆ Alloc() [2/2]

template<typename T >
T * Bond::Allocator::Alloc ( size_t  numElements)
inline

Allocates and returns a pointer to a block of uninitialized memory large enough to accomodate an array of objects of type T.

Parameters
numElementsThe number of elements in the allocated array.

◆ AllocAligned() [1/2]

template<typename T >
T * Bond::Allocator::AllocAligned ( size_t  align)
inline

Allocates and returns a pointer to a block of uninitialized aligned memory large enough to accomodate an object of type T.

Parameters
alignThe alignment requirements for the allocated memory.

◆ AllocAligned() [2/2]

template<typename T >
T * Bond::Allocator::AllocAligned ( size_t  numElements,
size_t  align 
)
inline

Allocates and returns a pointer to a block of uninitialized aligned memory large enough to accomodate an array of objects of type T.

Parameters
numElementsThe number of elements in the allocated array.
alignThe alignment requirements for the allocated memory.

◆ AllocAlignedObject()

template<typename T , typename... Args>
T * Bond::Allocator::AllocAlignedObject ( size_t  align,
Args &&...  args 
)
inline

Allocates, constructs and returns a pointer to an aligned instance of type T.

Parameters
alignThe alignment requirements for the allocated memory.
argsA list of arguments forwarded to the constructor of the instance of type T.

◆ Allocate()

virtual void * Bond::Allocator::Allocate ( size_t  size)
pure virtual

Allocates and returns a pointer to a block of uninitialized memory of the given size.

Implemented in Bond::DefaultAllocator.

◆ AllocateAligned()

virtual void * Bond::Allocator::AllocateAligned ( size_t  size,
size_t  align 
)
pure virtual

Allocates and returns a pointer to a block of uninitialized memory with the given size and alignment.

Implemented in Bond::DefaultAllocator.

◆ AllocObject()

template<typename T , typename... Args>
T * Bond::Allocator::AllocObject ( Args &&...  args)
inline

Allocates, constructs and returns a pointer to an instance of type T.

Parameters
argsA list of arguments forwarded to the constructor of the instance of type T.

◆ AllocOwned() [1/2]

template<typename T >
Handle< T > Bond::Allocator::AllocOwned ( )
inline

Allocates and returns an owning handle to a block of uninitialized memory large enough to accomodate an object of type T.

◆ AllocOwned() [2/2]

template<typename T >
Handle< T > Bond::Allocator::AllocOwned ( size_t  numElements)
inline

Allocates and returns an owning handle to a block of uninitialized memory large enough to accomodate an array of objects of type T.

Parameters
numElementsThe number of elements in the allocated array.

◆ AllocOwnedAligned() [1/2]

template<typename T >
AlignedHandle< T > Bond::Allocator::AllocOwnedAligned ( size_t  align)
inline

Allocates and returns an owning handle to a block of uninitialized aligned memory large enough to accomodate an object of type T.

Parameters
alignThe alignment requirements for the allocated memory.

◆ AllocOwnedAligned() [2/2]

template<typename T >
AlignedHandle< T > Bond::Allocator::AllocOwnedAligned ( size_t  numElements,
size_t  align 
)
inline

Allocates and returns an owning handle to a block of uninitialized aligned memory large enough to accomodate an array of objects of type T.

Parameters
numElementsThe number of elements in the allocated array.
alignThe alignment requirements for the allocated memory.

◆ AllocOwnedAlignedObject()

template<typename T , typename... Args>
AlignedObjectHandle< T > Bond::Allocator::AllocOwnedAlignedObject ( size_t  align,
Args &&...  args 
)
inline

Allocates, constructs and returns an owning handle to an aligned instance of type T.

Parameters
alignThe alignment requirements for the allocated memory.
argsA list of arguments forwarded to the constructor of the instance of type T.

◆ AllocOwnedObject()

template<typename T , typename... Args>
ObjectHandle< T > Bond::Allocator::AllocOwnedObject ( Args &&...  args)
inline

Allocates, constructs and returns an owning handle to an instance of type T.

Parameters
argsA list of arguments forwarded to the constructor of the instance of type T.

◆ Free() [1/2]

void Bond::Allocator::Free ( const void *  buffer)
inline

Calls the non-const form of Free after casting away the constness of the given pointer.

◆ Free() [2/2]

virtual void Bond::Allocator::Free ( void *  buffer)
pure virtual

Frees the memory pointed to by the given pointer. The memory must have been allocated by this allocator's Allocate method.

Implemented in Bond::DefaultAllocator.

◆ FreeAligned() [1/2]

void Bond::Allocator::FreeAligned ( const void *  buffer)
inline

Calls the non-const form of FreeAligned after casting away the constness of the given pointer.

◆ FreeAligned() [2/2]

virtual void Bond::Allocator::FreeAligned ( void *  buffer)
pure virtual

Frees the aligned memory pointed to by the given pointer. The memory must have been allocated by this allocator's Allocate method.

Implemented in Bond::DefaultAllocator.


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