ArenaAllocator#
Fully qualified name: carb::memory::ArenaAllocator
Defined in carb/memory/ArenaAllocator.h
Structs#
- rebind
Rebinds ArenaAllocator to a different type
U.
-
template<class T, class FallbackAllocator = std::allocator<T>>
class 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.
- Template Parameters:
T – The type allocated by this allocator.
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
FallbackAllocatoras no arena is given.
-
inline explicit ArenaAllocator(const FallbackAllocator &fallback)#
Constructs
ArenaAllocatorwith a specificFallbackAllocator.Only uses
FallbackAllocatoras no arena is given.- Parameters:
fallback – A
FallbackAllocatorinstance to copy.
- inline ArenaAllocator(
- void *begin,
- void *end,
- const FallbackAllocator &fallback = FallbackAllocator(),
Constructs
ArenaAllocatorwith an arena and optionally a specificFallbackAllocator.Warning
It is the caller’s responsibility to ensure that the given memory arena outlives
*thisand 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
FallbackAllocatorinstance to copy.
-
inline ArenaAllocator(ArenaAllocator &&other)#
Move constructor: constructs
ArenaAllocatorby moving from a differentArenaAllocator.- Parameters:
other – The
ArenaAllocatorto copy from.
-
inline ArenaAllocator(const ArenaAllocator &other)#
Copy constructor: constructs
ArenaAllocatorfrom a copy of a givenArenaAllocator.Note
Even though
otheris passed via const-reference, the arena is transferred fromotherto*this. Further allocations fromotherwill defer to the FallbackAllocator.- Parameters:
other – The
ArenaAllocatorto copy from.
-
template<class U, class UFallbackAllocator>
inline ArenaAllocator( - const ArenaAllocator<U, UFallbackAllocator> &other,
Copy constructor: constructs
ArenaAllocatorfor typeTfrom a copy of a givenArenaAllocatorfor typeU.Note
This does not copy the arena; that is retained by the original allocator.
- Parameters:
other – The
ArenaAllocatorto 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_typeinstances to allocate. If the request cannot be serviced by the arena, theFallbackAllocatoris used.- Throws:
Memory – Any exception that would be thrown by
FallbackAllocator.- Returns:
An uninitialized memory region that will fit
ncontiguous 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
nvalue that was passed to allocate() that producedin.
-
template<class U>
struct rebind# Rebinds ArenaAllocator to a different type
U.Public Types
-
using other = ArenaAllocator<U, typename FallbackAllocator::template rebind<U>::other>#
The rebound ArenaAllocator.
-
using other = ArenaAllocator<U, typename FallbackAllocator::template rebind<U>::other>#