33#ifndef DART_COMMON_MEMORYALLOCATOR_HPP_
34#define DART_COMMON_MEMORYALLOCATOR_HPP_
58 [[nodiscard]] virtual const std::
string&
getType() const = 0;
66 [[nodiscard]] virtual
void*
allocate(
size_t bytes) noexcept = 0;
75 [[nodiscard]] T*
allocateAs(
size_t n = 1) noexcept;
82 virtual
void deallocate(
void* pointer,
size_t bytes) = 0;
92 template <typename T, typename... Args>
93 [[nodiscard]] T*
construct(Args&&... args) noexcept;
95 template <typename T, typename... Args>
96 [[nodiscard]] T*
constructAt(
void* pointer, Args&&... args);
98 template <typename T, typename... Args>
99 [[nodiscard]] T*
constructAt(T* pointer, Args&&... args);
102 template <typename T>
103 void destroy(T*
object) noexcept;
106 virtual
void print(std::ostream& os = std::cout,
int indent = 0) const;
109 friend std::ostream& operator<<(
115#include "dart/common/detail/MemoryAllocator-impl.hpp"
A CRTP base class that provides an interface for easily casting to the derived types.
Definition Castable.hpp:58
Base class for std::allocator compatible allocators.
Definition MemoryAllocator.hpp:46
virtual void * allocate(size_t bytes) noexcept=0
Allocates size bytes of uninitialized storage.
virtual void print(std::ostream &os=std::cout, int indent=0) const
Prints state of the memory allocator.
Definition MemoryAllocator.cpp:48
void destroy(T *object) noexcept
Calls the destructor of the object and deallocate the storage.
Definition MemoryAllocator-impl.hpp:90
virtual void deallocate(void *pointer, size_t bytes)=0
Deallocates the storage referenced by the pointer p, which must be a pointer obtained by an earlier c...
T * constructAt(void *pointer, Args &&... args)
Definition MemoryAllocator-impl.hpp:74
MemoryAllocator() noexcept=default
Default constructor.
T * construct(Args &&... args) noexcept
Allocates uninitialized storage and constructs an object of type T to the allocated storage.
Definition MemoryAllocator-impl.hpp:49
static MemoryAllocator & GetDefault()
Returns the default memory allocator.
Definition MemoryAllocator.cpp:41
virtual const std::string & getType() const =0
Returns type string.
T * allocateAs(size_t n=1) noexcept
Allocates object(s) without calling the constructor.
Definition MemoryAllocator-impl.hpp:42