carb::memory::ArenaAllocator¶
Defined in carb/memory/ArenaAllocator.h
-
template<class
T
, classFallbackAllocator
= std::allocator<T>>
classcarb::memory
::
ArenaAllocator
¶ An allocator that initially allocates from a memory arena (typically on the stack) and falls back to another allocator when that is exhausted.
ArenaAllocator conforms to the C++ Named Requirement of Allocator.
- tparam T
The type allocated by this allocator.
- tparam FallbackAllocator
The Allocator that is used when the arena is exhausted.
Public Types
-
using
pointer
= typename std::allocator_traits<FallbackAllocator>::pointer¶ T*
-
using
const_pointer
= typename std::allocator_traits<FallbackAllocator>::const_pointer¶ T const*
-
using
void_pointer
= typename std::allocator_traits<FallbackAllocator>::void_pointer¶ void*
-
using
const_void_pointer
= typename std::allocator_traits<FallbackAllocator>::const_void_pointer¶ void const*
-
using
value_type
= typename std::allocator_traits<FallbackAllocator>::value_type¶ T
-
using
size_type
= typename std::allocator_traits<FallbackAllocator>::size_type¶ std::size_t
-
using
difference_type
= typename std::allocator_traits<FallbackAllocator>::difference_type¶ std::ptrdiff_t
Public Functions
-
inline
ArenaAllocator
()¶ Default constructor.
Only uses
FallbackAllocator
as no arena is given.
-
inline explicit
ArenaAllocator
(const FallbackAllocator &fallback)¶ Constructs
ArenaAllocator
with a specificFallbackAllocator
.Only uses
FallbackAllocator
as no arena is given.- Parameters
fallback – A
FallbackAllocator
instance to copy.
-
inline
ArenaAllocator
(void *begin, void *end, const FallbackAllocator &fallback = FallbackAllocator())¶ Constructs
ArenaAllocator
with an arena and optionally a specificFallbackAllocator
.Warning
It is the caller’s responsibility to ensure that the given memory arena outlives
*this
and any other ArenaAllocator which it may be moved to.- Parameters
begin – A pointer to the beginning of the arena.
end – A pointer immediately past the end of the arena.
fallback – A
FallbackAllocator
instance to copy.
-
inline
ArenaAllocator
(ArenaAllocator &&other)¶ Move constructor: constructs
ArenaAllocator
by moving from a differentArenaAllocator
.- Parameters
other – The
ArenaAllocator
to copy from.
-
inline
ArenaAllocator
(const ArenaAllocator &other)¶ Copy constructor: constructs
ArenaAllocator
from a copy of a givenArenaAllocator
.Note
Even though
other
is passed via const-reference, the arena is transferred fromother
to*this
. Further allocations fromother
will defer to the FallbackAllocator.- Parameters
other – The
ArenaAllocator
to copy from.
-
template<class
U
, classUFallbackAllocator
>
inlineArenaAllocator
(const ArenaAllocator<U, UFallbackAllocator> &other)¶ Copy constructor: constructs
ArenaAllocator
for typeT
from a copy of a givenArenaAllocator
for typeU
.Note
This does not copy the arena; that is retained by the original allocator.
- Parameters
other – The
ArenaAllocator
to copy from.
-
inline pointer
allocate
(size_type n = 1)¶ Allocates (but does not construct) memory for one or more instances of
value_type
.- Parameters
n – The number of contiguous
value_type
instances to allocate. If the request cannot be serviced by the arena, theFallbackAllocator
is used.- Throws
Memory – Any exception that would be thrown by
FallbackAllocator
.- Returns
An uninitialized memory region that will fit
n
contiguous instances ofvalue_type
.
-
inline void
deallocate
(pointer in, size_type n = 1)¶ Deallocates (but does not destruct) memory for one or more instances of
value_type
.Note
If the memory came from the arena, the memory will not be available for reuse unless the memory is the most recent allocation from the arena.
- Parameters
in – The pointer previously returned from allocate().
n – The same
n
value that was passed to allocate() that producedin
.
-
template<class
U
>
structrebind
¶ Rebinds ArenaAllocator to a different type
U
.Public Types
-
using
other
= ArenaAllocator<U, typename FallbackAllocator::template rebind<U>::other>¶ The rebound ArenaAllocator.
-
using