57 template<
size_t Size = kDefaultStackArenaSize>
struct StackArena {
58 alignas(std::max_align_t) std::byte
data[
Size];
59 constexpr operator Arena() {
return {
reinterpret_cast<void*
>(
data),
Size }; }
60 constexpr operator Arena()
const {
return {
reinterpret_cast<void*
>(
data),
Size }; }
77 template <
typename T =
void>
106 return lhs.mResource ==
rhs.mResource;
116 template <
typename T>
121 std::destroy_at(ptr);
131 template <
typename Base,
typename Derived,
typename ...Args>
148 template <
typename T,
typename ...Args>
155 template <
typename T>
165 template<
typename T,
typename Deleter = StlDeleter<T>>
174 template <
typename Base,
typename Derived,
typename ...Args>
184 template <
typename T,
typename ...Args>
201 template<
typename Base,
typename Derived,
typename ...Args>
212 template <
typename T,
typename ...Args>
221#define GLOBAL_ALLOC Foundation::Core::getGlobalAllocator()
General Purpose Allocator (GPA) interface.
Definition Allocator.hpp:24
Arena AllocateArena(size_type size)
Definition Allocator.hpp:34
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:33
void DeallocateArena(Arena arena)
Definition Allocator.hpp:35
Allocator * Ptr()
Definition Allocator.hpp:39
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:213
UniquePtr< T > ConstructUnique(Allocator *resource, Args &&...args)
Convenience wrapper for calling ConstructUniqueBase when Base and Derived are the same type.
Definition Allocator.hpp:185
Allocator * getGlobalAllocator()
Definition AllocatorHeap.cpp:47
UniquePtr< Base > ConstructUniqueBase(Allocator *resource, Args &&...args)
Helper function for constructing a pinned resource with a Foundation::Core::Allocator.
Definition Allocator.hpp:175
constexpr uintptr_t AlignUp(const uintptr_t value, const uintptr_t alignment)
Definition Allocator.hpp:8
constexpr size_t kDefaultStackArenaSize
Definition Allocator.hpp:53
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:156
std::shared_ptr< T > SharedPtr
std::shared_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:193
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:132
std::unique_ptr< T, Deleter > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:166
SharedPtr< Base > ConstructSharedBase(Allocator *resource, Args &&...args)
Helper function for constructing a ref-counted resource with a Foundation::Core::Allocator.
Definition Allocator.hpp:202
T * Construct(Allocator *resource, Args &&...args)
Convenience placement new with object of type T using a Foundation::Core::Allocator.
Definition Allocator.hpp:149
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:44
Allocator * resource
Definition Allocator.hpp:45
Arena arena
Definition Allocator.hpp:46
~ScopedArena()
Definition Allocator.hpp:49
ScopedArena(Allocator *res, size_t size, size_t alignment=alignof(std::max_align_t))
Definition Allocator.hpp:47
A fixed-size stack memory arena.
Definition Allocator.hpp:57
std::byte data[Size]
Definition Allocator.hpp:58
Definition Allocator.hpp:90
std::allocator adaptor for Foundation::Core::Allocator
Definition Allocator.hpp:78
StlAllocator(const StlAllocator< U > &other) noexcept
Definition Allocator.hpp:93
StlAllocator(Allocator *resource) noexcept
Definition Allocator.hpp:91
friend bool operator==(const StlAllocator &lhs, const StlAllocator &rhs) noexcept
Definition Allocator.hpp:105
T & reference
Definition Allocator.hpp:84
void deallocate(pointer p, size_type n) noexcept
Definition Allocator.hpp:98
const T * const_pointer
Definition Allocator.hpp:83
friend bool operator!=(const StlAllocator &lhs, const StlAllocator &rhs) noexcept
Definition Allocator.hpp:108
pointer allocate(size_type n)
Definition Allocator.hpp:95
Allocator * mResource
Definition Allocator.hpp:87
std::size_t size_type
Definition Allocator.hpp:80
void deallocate(pointer p) noexcept
Definition Allocator.hpp:101
T * pointer
Definition Allocator.hpp:82
std::ptrdiff_t difference_type
Definition Allocator.hpp:81
const T & const_reference
Definition Allocator.hpp:85
T value_type
Definition Allocator.hpp:79
Custom deleter for Foundation::Core::UniquePtr and Foundation::Core::SharedPtr that uses a Foundation...
Definition Allocator.hpp:117
Allocator * mResource
Definition Allocator.hpp:118
void operator()(T *ptr) noexcept
Definition Allocator.hpp:119