template <typename AllocateFunction>
class BasicLeakyAllocator
Defined at line 60 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
This is the most basic trivial allocator class on which others are built.
It exemplifies the basic API they all share. This is a move-only object
(move-constructible and/or move-assignable if AllocateFunction is so) that
contains an AllocateFunction object (see below).
It has a basic allocate method that takes a size in bytes and an optional
alignment, and returns void*. It has a deallocate method that takes void*
and a pointer passed to deallocate must not be used any further. But there
is no real expectation of reusing or releasing any memory during the life of
the allocator object. Instead, a separate allocator object can be used for
each set of purposes whose lifetime management is circumscribed together.
That is, all allocations are expected to live for at least the lifetime of
the allocator object.
See
<lib
/trivial-allocator/typed-allocator.h> for the wrapper class
trivial_allocator::TypedAllocator to turn this into something fit for
std::allocator_traits and
<lib
/trivial-allocator/new.h> for variants of the
C++ new operator using a BasicLeakyAllocator or one of its derivatives.
AllocateFunction is some type callable as `(size_t
&
size, size_t alignment)`
to use uses some underlying allocator. It should fail if size bytes cannot
be allocated, but the alignment is only best-available and it may return a
less-aligned pointer if it can't do any better. It is expected to update
size to increase the size of the allocation for its convenience and to
amortize the cost of calling the AllocateFunction repeatedly.
The return value from AllocateFunction is some object that has roughly the
basic API of std::unique_ptr
<std
::byte>: moveable, default-constructible,
contextually convertible to bool, and with get() and release() methods that
return std::byte* or void*.
Note that though it uses this smart-pointer type for the AllocateFunction
interface, BasicLeakyAllocator always just leaks the underlying allocations
used in live blocks it hands out. That is, it calls release() on the
returned object except in error recovery cases. Some derivative classes can
keep track of allocations and destroy them all when the allocator is
destroyed.
Public Methods
void BasicLeakyAllocator<AllocateFunction> ()
Defined at line 65 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
void BasicLeakyAllocator<AllocateFunction> (const BasicLeakyAllocator<AllocateFunction> & )
Defined at line 67 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
void BasicLeakyAllocator<AllocateFunction> (std::enable_if_t<std::is_move_constructible_v<AllocateFunction>, BasicLeakyAllocator<AllocateFunction> &&> other)
Defined at line 69 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
void BasicLeakyAllocator<T> (std::enable_if_t<std::is_move_constructible_v<AllocateFunction>, BasicLeakyAllocator<AllocateFunction> &&> other)
Defined at line 69 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
template <typename... Args>
void BasicLeakyAllocator<AllocateFunction> (Args &&... args)
Defined at line 79 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
BasicLeakyAllocator<AllocateFunction> & operator= (std::enable_if_t<std::is_move_constructible_v<AllocateFunction>, BasicLeakyAllocator<AllocateFunction> &&> other)
Defined at line 81 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
BasicLeakyAllocator<AllocateFunction> & operator= (std::enable_if_t<std::is_move_constructible_v<AllocateFunction>, BasicLeakyAllocator<AllocateFunction> &&> other)
Defined at line 81 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
void * allocate (size_t size, size_t alignment)
Defined at line 91 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
void * allocate (size_t size, size_t alignment)
Defined at line 91 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
void deallocate (void * ptr)
Defined at line 129 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
AllocateFunction & allocate_function ()
Defined at line 143 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
const AllocateFunction & allocate_function ()
Defined at line 144 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h
cpp20::span<const std::byte> unallocated ()
Defined at line 146 of file ../../src/lib/trivial-allocator/include/lib/trivial-allocator/basic-leaky-allocator.h