SuperDex Physics C++ API
Loading...
Searching...
No Matches
superdex::Allocator Class Referenceabstract

Virtual interface class for memory allocation and deallocation. More...

#include <allocator.h>

Inheritance diagram for superdex::Allocator:
superdex::DefaultAllocator

Public Member Functions

void * allocate (std::size_t sizeInBytes, std::size_t alignment=alignof(std::max_align_t))
 Allocate memory of the specified size and alignment.
void deallocate (void *ptr, std::size_t sizeInBytes, std::size_t alignment=alignof(std::max_align_t))
 Deallocate a block of memory that was previously allocated by this Allocator instance or by a compatible Allocator instance.
bool is_equal (Allocator const &other) const noexcept
 Return true if memory allocated by this Allocator instance can be deallocated by the other Allocator instance, and visa versa.
virtual ~Allocator ()=default

Protected Member Functions

virtual void * do_allocate (std::size_t sizeInBytes, std::size_t alignment)=0
virtual void do_deallocate (void *ptr, std::size_t sizeInBytes, std::size_t alignment)=0
virtual bool do_is_equal (Allocator const &other) const noexcept=0

Detailed Description

Virtual interface class for memory allocation and deallocation.

This class provides a polymorphic interface for memory allocation operations, similar to std::pmr::memory_resource, which is not used because of compatibility issues with various platform/compiler combinations. Derived classes must implement the protected members.

Definition at line 47 of file allocator.h.

Constructor & Destructor Documentation

◆ ~Allocator()

virtual superdex::Allocator::~Allocator ( )
virtualdefault

Member Function Documentation

◆ allocate()

void * superdex::Allocator::allocate ( std::size_t sizeInBytes,
std::size_t alignment = alignof(std::max_align_t) )
inline

Allocate memory of the specified size and alignment.

Parameters
sizeInBytes
alignmentMust be a power of 2.
Returns
void*
Exceptions
std::bad_alloc
Note
The caller is responsible for deallocating the memory by calling the deallocate method on the same Allocator instance, or a compatible Allocator instance.
See also
deallocate
is_equal

Definition at line 95 of file allocator_inl.h.

◆ deallocate()

void superdex::Allocator::deallocate ( void * ptr,
std::size_t sizeInBytes,
std::size_t alignment = alignof(std::max_align_t) )
inline

Deallocate a block of memory that was previously allocated by this Allocator instance or by a compatible Allocator instance.

Parameters
ptrAddress of the memory block to deallocate.
sizeInBytesMust match the size that was passed to the allocate method.
alignmentMust match the alignment that was passed to the allocate method.
See also
allocate
is_equal

Definition at line 107 of file allocator_inl.h.

◆ do_allocate()

virtual void * superdex::Allocator::do_allocate ( std::size_t sizeInBytes,
std::size_t alignment )
protectedpure virtual

◆ do_deallocate()

virtual void superdex::Allocator::do_deallocate ( void * ptr,
std::size_t sizeInBytes,
std::size_t alignment )
protectedpure virtual

◆ do_is_equal()

virtual bool superdex::Allocator::do_is_equal ( Allocator const & other) const
protectedpure virtualnoexcept

◆ is_equal()

bool superdex::Allocator::is_equal ( Allocator const & other) const
inlinenoexcept

Return true if memory allocated by this Allocator instance can be deallocated by the other Allocator instance, and visa versa.

Parameters
other
Returns
bool

Definition at line 115 of file allocator_inl.h.


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