9 return value % alignment ? (value + alignment - value % alignment) : value;
12 return value % alignment ? (value - value % alignment) : value;
31 virtual void QueryBudget(
size_t& used,
size_t& budget)
const = 0;
58 template<
size_t Size = kDefaultStackArenaSize>
struct StackArena {
59 alignas(std::max_align_t) std::byte
data[Size];
60 constexpr operator Arena() {
return {
reinterpret_cast<void*
>(
data), Size }; }
61 constexpr operator Arena()
const {
return {
reinterpret_cast<void*
>(
data), Size }; }
78 template <
typename T =
void>
107 return lhs.mResource ==
rhs.mResource;
117 template <
typename T>
125 std::destroy_at(ptr);
135 template <
typename Base,
typename Derived,
typename ...Args>
152 template <
typename T,
typename ...Args>
159 template <
typename T>
169 template<
typename T,
typename Deleter = StlDeleter<T>>
178 template <
typename Base,
typename Derived,
typename ...Args>
188 template <
typename T,
typename ...Args>
205 template<
typename Base,
typename Derived,
typename ...Args>
216 template <
typename T,
typename ...Args>
225#define GLOBAL_ALLOC Foundation::Core::getGlobalAllocator()
General Purpose Allocator (GPA) interface.
Definition Allocator.hpp:24
Arena AllocateArena(size_type size)
Definition Allocator.hpp:35
virtual pointer Reallocate(pointer ptr, size_type new_size, size_t alignment)=0
virtual ~Allocator()=default
virtual void QueryBudget(size_t &used, size_t &budget) const =0
virtual void Deallocate(pointer ptr)=0
Arena AllocateArena(size_type size, size_t alignment)
Definition Allocator.hpp:34
void DeallocateArena(Arena arena)
Definition Allocator.hpp:36
Allocator * Ptr()
Definition Allocator.hpp:40
virtual size_t QueryHeapUsage() const =0
virtual pointer Allocate(size_type size, size_t alignment=alignof(std::max_align_t))=0
Lock-free atomic primitives and implementations of data structures.
Definition Allocator.hpp:5
std::size_t size_type
Definition Allocator.hpp:6
SharedPtr< T > ConstructShared(Allocator *resource, Args &&...args)
Convenience wrapper for calling ConstructSharedBase when Base and Derived are the same type.
Definition Allocator.hpp:217
UniquePtr< T > ConstructUnique(Allocator *resource, Args &&...args)
Convenience wrapper for calling ConstructUniqueBase when Base and Derived are the same type.
Definition Allocator.hpp:189
Allocator * getGlobalAllocator()
Definition AllocatorHeap.cpp:109
UniquePtr< Base > ConstructUniqueBase(Allocator *resource, Args &&...args)
Helper function for constructing a pinned resource with a Foundation::Core::Allocator.
Definition Allocator.hpp:179
constexpr uintptr_t AlignUp(const uintptr_t value, const uintptr_t alignment)
Definition Allocator.hpp:8
constexpr size_t kDefaultStackArenaSize
Definition Allocator.hpp:54
constexpr uintptr_t AlignDown(const uintptr_t value, const uintptr_t alignment)
Definition Allocator.hpp:11
void Destruct(Allocator *resource, T *obj)
Convenience destructor for objects allocated with Construct or ConstructBase.
Definition Allocator.hpp:160
std::shared_ptr< T > SharedPtr
std::shared_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:197
void * pointer
Definition Allocator.hpp:7
Base * ConstructBase(Allocator *resource, Args &&...args)
Placement new helper for constructing an object of type Derived (which can be a subclass of Base) usi...
Definition Allocator.hpp:136
std::unique_ptr< T, Deleter > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:170
SharedPtr< Base > ConstructSharedBase(Allocator *resource, Args &&...args)
Helper function for constructing a ref-counted resource with a Foundation::Core::Allocator.
Definition Allocator.hpp:206
T * Construct(Allocator *resource, Args &&...args)
Convenience placement new with object of type T using a Foundation::Core::Allocator.
Definition Allocator.hpp:153
A memory arena allocated from an Allocator.
Definition Allocator.hpp:17
size_type size
Definition Allocator.hpp:19
pointer memory
Definition Allocator.hpp:18
RAII wrapper for an arena allocated from an Allocator.
Definition Allocator.hpp:45
Allocator * resource
Definition Allocator.hpp:46
Arena arena
Definition Allocator.hpp:47
~ScopedArena()
Definition Allocator.hpp:50
ScopedArena(Allocator *res, size_t size, size_t alignment=alignof(std::max_align_t))
Definition Allocator.hpp:48
A fixed-size stack memory arena.
Definition Allocator.hpp:58
std::byte data[Size]
Definition Allocator.hpp:59
Definition Allocator.hpp:91
std::allocator adaptor for Foundation::Core::Allocator
Definition Allocator.hpp:79
StlAllocator(const StlAllocator< U > &other) noexcept
Definition Allocator.hpp:94
StlAllocator(Allocator *resource) noexcept
Definition Allocator.hpp:92
friend bool operator==(const StlAllocator &lhs, const StlAllocator &rhs) noexcept
Definition Allocator.hpp:106
T & reference
Definition Allocator.hpp:85
void deallocate(pointer p, size_type n) noexcept
Definition Allocator.hpp:99
const T * const_pointer
Definition Allocator.hpp:84
friend bool operator!=(const StlAllocator &lhs, const StlAllocator &rhs) noexcept
Definition Allocator.hpp:109
pointer allocate(size_type n)
Definition Allocator.hpp:96
Allocator * mResource
Definition Allocator.hpp:88
std::size_t size_type
Definition Allocator.hpp:81
void deallocate(pointer p) noexcept
Definition Allocator.hpp:102
T * pointer
Definition Allocator.hpp:83
std::ptrdiff_t difference_type
Definition Allocator.hpp:82
const T & const_reference
Definition Allocator.hpp:86
T value_type
Definition Allocator.hpp:80
Custom deleter for Foundation::Core::UniquePtr and Foundation::Core::SharedPtr that uses a Foundation...
Definition Allocator.hpp:118
Allocator * mResource
Definition Allocator.hpp:119
void operator()(T *ptr) noexcept
Definition Allocator.hpp:120