9 return (value + alignment - 1) & ~(alignment - 1);
12 return (value) & ~(alignment - 1);
56 template<
size_t Size = kDefaultStackArenaSize>
struct StackArena {
57 alignas(std::max_align_t) std::byte
data[Size];
58 constexpr operator Arena() {
return {
reinterpret_cast<void*
>(
data), Size }; }
59 constexpr operator Arena()
const {
return {
reinterpret_cast<void*
>(
data), Size }; }
76 template <
typename T =
void>
105 return lhs.mResource ==
rhs.mResource;
115 template <
typename T>
120 std::destroy_at(
ptr);
128 template <
typename Base,
typename Derived,
typename ...Args>
143 template <
typename T,
typename ...Args>
150 template <
typename T>
169 template <
typename Base,
typename Derived,
typename ...Args>
179 template <
typename T,
typename ...Args>
196 template<
typename Base,
typename Derived,
typename ...Args>
207 template <
typename T,
typename ...Args>
General Purpose Allocator (GPA) interface.
Definition Allocator.hpp:24
Arena AllocateArena(size_type size)
Definition Allocator.hpp:33
virtual pointer Reallocate(pointer ptr, size_type new_size, size_t alignment)=0
virtual ~Allocator()=default
virtual void Deallocate(pointer ptr)=0
virtual void Deallocate(pointer ptr, size_type size)=0
Arena AllocateArena(size_type size, size_t alignment)
Definition Allocator.hpp:32
void DeallocateArena(Arena arena)
Definition Allocator.hpp:34
Allocator * Ptr()
Definition Allocator.hpp:38
virtual pointer Allocate(size_type size, size_t alignment=alignof(std::max_align_t))=0
std::allocator adaptor for Foundation::Core::Allocator
Definition Allocator.hpp:77
StlAllocator(const StlAllocator< U > &other) noexcept
Definition Allocator.hpp:92
StlAllocator(Allocator *resource) noexcept
Definition Allocator.hpp:90
friend bool operator==(const StlAllocator &lhs, const StlAllocator &rhs) noexcept
Definition Allocator.hpp:104
T & reference
Definition Allocator.hpp:85
void deallocate(pointer p, size_type n) noexcept
Definition Allocator.hpp:97
const T * const_pointer
Definition Allocator.hpp:84
friend bool operator!=(const StlAllocator &lhs, const StlAllocator &rhs) noexcept
Definition Allocator.hpp:107
pointer allocate(size_type n)
Definition Allocator.hpp:94
Allocator * mResource
Definition Allocator.hpp:78
std::size_t size_type
Definition Allocator.hpp:81
void deallocate(pointer p) noexcept
Definition Allocator.hpp:100
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
Allocators, Data Structures and introspection implementations.
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:208
UniquePtr< T > ConstructUnique(Allocator *resource, Args &&...args)
Convenience wrapper for calling ConstructUniqueBase when Base and Derived are the same type.
Definition Allocator.hpp:180
UniquePtr< Base > ConstructUniqueBase(Allocator *resource, Args &&...args)
Helper function for constructing a pinned resource with a Foundation::Core::Allocator.
Definition Allocator.hpp:170
constexpr size_t kDefaultStackArenaSize
Definition Allocator.hpp:52
uintptr_t AlignUp(uintptr_t value, uintptr_t alignment)
Definition Allocator.hpp:8
void Destruct(Allocator *resource, T *obj)
Convenience destructor for objects allocated with Construct or ConstructBase.
Definition Allocator.hpp:151
uintptr_t AlignDown(uintptr_t value, uintptr_t alignment)
Definition Allocator.hpp:11
std::shared_ptr< T > SharedPtr
std::shared_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:188
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:129
SharedPtr< Base > ConstructSharedBase(Allocator *resource, Args &&...args)
Helper function for constructing a ref-counted resource with a Foundation::Core::Allocator.
Definition Allocator.hpp:197
T * Construct(Allocator *resource, Args &&...args)
Convenience placement new with object of type T using a Foundation::Core::Allocator.
Definition Allocator.hpp:144
std::unique_ptr< T, StlDeleter< T > > UniquePtr
std::unique_ptr with custom deleter that uses a Foundation::Core::Allocator to deallocate memory.
Definition Allocator.hpp:161
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:43
Allocator * resource
Definition Allocator.hpp:44
Arena arena
Definition Allocator.hpp:45
~ScopedArena()
Definition Allocator.hpp:48
ScopedArena(Allocator *res, size_t size, size_t alignment=alignof(std::max_align_t))
Definition Allocator.hpp:46
A fixed-size stack memory arena.
Definition Allocator.hpp:56
std::byte data[Size]
Definition Allocator.hpp:57
Definition Allocator.hpp:89
StlAllocator< U > other
Definition Allocator.hpp:89
Custom deleter for Foundation::Core::UniquePtr and Foundation::Core::SharedPtr that uses a Foundation...
Definition Allocator.hpp:116
Allocator * mResource
Definition Allocator.hpp:117
void operator()(T *ptr) noexcept
Definition Allocator.hpp:118