Template Class PoolAllocator¶
Defined in File pool_allocator.hpp
Class Documentation¶
-
template<size_t
ElementSize
, size_tAlignment
, typenameFreelistImpl
= Freelist>
classwrench
::
PoolAllocator
¶ Allocator to allocate elements of size ElementSize, with a given Alignment, and using the given FreelistImpl. We don’t use a templated type for the pooled allocator to allow the allocator to allocate elements of different types but which are the same size, or smaller, than the element size for the pool.
This allocator should be used as an allocator implementation in the Allocator class, which will allow typed objects to be allocated.
- Template Parameters
ElementSize
: The byte size of the elements in the pool.Alignment
: The alignment for the elements.FreelistImpl
: The implementation type of the freelist.
Public Functions
-
PoolAllocator
() noexcept = delete¶ Default constructor for the pool.
-
~PoolAllocator
() noexcept = default¶ Default destructor for the pool.
-
PoolAllocator
(const void *begin, const void *end) noexcept¶ Constructor which initializes the freelist with the
start
andend
pointers to the memory arena for the pool.- Parameters
begin
: A pointer to the start of the arena for the pool.end
: A pointer to the end of the arena for the pool.
-
template<typename
Arena
>PoolAllocator
(const Arena &arena) noexcept¶ Constructor to initialize the allocator with the arena to allocator from.
- Parameters
arena
: The arena for allocation.
- Template Parameters
Arena
: The type of the arena.
-
PoolAllocator
(PoolAllocator &&other) noexcept = default¶ Moves constructor to move
other
into this allocator.- Parameters
other
: The other allocator to move into this one.
-
auto operator= (PoolAllocator &&other) noexcept -> PoolAllocator &=default
Move assignment operator to move
other
into this allocator.- Parameters
other
: The other allocator to move into this one.
-
PoolAllocator
(const PoolAllocator&) = delete¶ Copy constructor deleted, allocators can’t be copied.
-
auto operator= (const PoolAllocator &) -> PoolAllocator &=delete
Copy assignment deleted, allocators can’t be copied.
-
auto alloc (size_t size=element_size, size_t align=alignment) noexcept -> void *
Allocates an element of
size
with a givenalignment
from the pool. This will fail ifsize
is larger than the element size for the pool or if the alignment is larger than the alignment for the pool.If the pool is full, this will return a nullptr.
- Parameters
size
: The size of the element to allocate.align
: The alignment for the allocation.
-
auto free (void *ptr, size_t=element_size) noexcept -> void
Frees the
ptr
, pushing it onto the front of the freelist.- Parameters
ptr
: The pointer to free.
-
auto owns (void *ptr) const noexcept -> bool
Returns true if the allocator owns the
ptr
.- Parameters
ptr
: The pointer to determine if is owned by the allocator.
-
auto reset () noexcept -> void
Resets the pool, if the freelist supports resetting.
Public Static Attributes
-
constexpr bool
resettable
= FreelistImpl::resettable¶ Specifies that the allocator cannot reset.