19#ifndef WPIUTIL_WPI_ALLOCATORBASE_H
20#define WPIUTIL_WPI_ALLOCATORBASE_H
23#define LLVM_ALLOCATORHOLDER_EMPTYBASE __declspec(empty_bases)
25#define LLVM_ALLOCATORHOLDER_EMPTYBASE
44 void *
Allocate(
size_t Size,
size_t Alignment) {
46 static_assert(
static_cast<void *(
AllocatorBase::*)(
size_t,
size_t)
>(
48 static_cast<void *(DerivedT::*)(
size_t,
size_t)
>(
50 "Class derives from AllocatorBase without implementing the "
51 "core Allocate(size_t, size_t) overload!");
53 return static_cast<DerivedT *
>(
this)->
Allocate(Size, Alignment);
58 void Deallocate(
const void *Ptr,
size_t Size,
size_t Alignment) {
61 static_cast<void (
AllocatorBase::*)(
const void *,
size_t,
size_t)
>(
63 static_cast<void (DerivedT::*)(
const void *,
size_t,
size_t)
>(
64 &DerivedT::Deallocate),
65 "Class derives from AllocatorBase without implementing the "
66 "core Deallocate(void *) overload!");
68 return static_cast<DerivedT *
>(
this)->
Deallocate(Ptr, Size, Alignment);
75 template <
typename T> T *
Allocate(
size_t Num = 1) {
76 return static_cast<T *
>(
Allocate(Num *
sizeof(T),
alignof(T)));
81 std::enable_if_t<!std::is_same_v<std::remove_cv_t<T>,
void>,
void>
83 Deallocate(
static_cast<const void *
>(Ptr), Num *
sizeof(T),
alignof(T));
98 void Deallocate(
const void *Ptr,
size_t Size,
size_t Alignment) {
#define LLVM_ATTRIBUTE_RETURNS_NONNULL
Definition: Compiler.h:277
This file defines counterparts of C library allocation functions defined in the namespace 'std'.
CRTP base class providing obvious overloads for the core Allocate() methods of LLVM-style allocators.
Definition: AllocatorBase.h:40
void * Allocate(size_t Size, size_t Alignment)
Allocate Size bytes of Alignment aligned memory.
Definition: AllocatorBase.h:44
std::enable_if_t<!std::is_same_v< std::remove_cv_t< T >, void >, void > Deallocate(T *Ptr, size_t Num=1)
Deallocate space for a sequence of objects without constructing them.
Definition: AllocatorBase.h:82
T * Allocate(size_t Num=1)
Allocate space for a sequence of objects without constructing them.
Definition: AllocatorBase.h:75
void Deallocate(const void *Ptr, size_t Size, size_t Alignment)
Deallocate Ptr to Size bytes of memory allocated by this allocator.
Definition: AllocatorBase.h:58
Definition: AllocatorBase.h:87
void PrintStats() const
Definition: AllocatorBase.h:105
LLVM_ATTRIBUTE_RETURNS_NONNULL void * Allocate(size_t Size, size_t Alignment)
Definition: AllocatorBase.h:91
void Reset()
Definition: AllocatorBase.h:89
void Deallocate(const void *Ptr, size_t Size, size_t Alignment)
Definition: AllocatorBase.h:98
const Alloc & getAllocator() const
Definition: AllocatorBase.h:125
AllocatorHolder(Alloc &A)
Definition: AllocatorBase.h:123
Alloc & getAllocator()
Definition: AllocatorBase.h:124
Definition: AllocatorBase.h:110
AllocatorHolder(const Alloc &A)
Definition: AllocatorBase.h:113
const Alloc & getAllocator() const
Definition: AllocatorBase.h:116
AllocatorHolder()=default
AllocatorHolder(Alloc &&A)
Definition: AllocatorBase.h:114
Alloc & getAllocator()
Definition: AllocatorBase.h:115
detail namespace with internal helper functions
Definition: xchar.h:20
Definition: ntcore_cpp.h:26
void deallocate_buffer(void *Ptr, size_t Size, size_t Alignment)
Deallocate a buffer of memory with the given size and alignment.
LLVM_ATTRIBUTE_RETURNS_NONNULL LLVM_ATTRIBUTE_RETURNS_NOALIAS void * allocate_buffer(size_t Size, size_t Alignment)
Allocate a buffer of memory with the given size and alignment.