Template Class Allocator¶
Defined in File allocator.hpp
Class Documentation¶
-
template<typename
PrimaryAllocator
, typenameArena
, typenameFallbackAllocator
, typenameLockingPolicy
>
classripple
::
Allocator
¶ The Allocator type is a simple implementation which allows an allocator to be composed of other allocators, to create allocators with useful properties for different contexts.
The allocator will always try to allocate from the primary allocator, unless the primary allocation fails, in which case it will allocate from the fallback allocator.
All allocation and free operations are locked, using the locking policy provided. The default locking policy is to not lock.
The allocator will always try to allocate from the primary allocator, unless the primary allocation fails, in which case it will allocate from the fallback allocator.
- Template Parameters
PrimaryAllocator
: The type of the primary allocator.Arena
: The type of the arena for the allocator.FallbackAllocator
: The type of the fallback allocator.LockingPolicy
: The type of the locking policy.
All allocation and free operations are locked, using the locking policy provided. The default locking policy is to not lock.
- Note
The fallback allocator should always success unless there is no system memory left to allocate from.
- Template Parameters
PrimaryAllocator
: The type of the primary allocator.Arena
: The type of the arena for the allocator.FallbackAllocator
: The type of the fallback allocator.LockingPolicy
: The type of the locking policy.
Public Types
-
using
Guard
= std::lock_guard<LockingPolicy>¶ Defines the type of the lock guard.
Public Functions
-
template<typename ...
Args
>Allocator
(size_t size, Args&&... args)¶ Constructor which sets the size of the arena, if the arena requires a size, and forwards the args to the primary allocator for construction.
- Note
If the arena has a constant size, then it will be created with that size and the size argument will be ignored.
- Parameters
size
: The size of the arena.args
: The arguments fro the primary allocator.
- Template Parameters
Args
: The types of arguments for the primary allocator.
-
~Allocator
() noexcept = default¶ Default destructor composed allocators know how to clean themselves up.
-
Allocator
(Allocator &&other) noexcept = default¶ Move constructor, defaulted.
- Parameters
other
: The other allocator to move into this one.
-
auto
operator=
(Allocator &&other) noexcept -> Allocator& = default¶ Move assignment, defaulted.
- Parameters
other
: The other allocator to move into this one.
-
auto
alloc
(size_t size, size_t alignment = alignof(std::max_align_t)) noexcept -> void*¶ Allocates the given number of bytes of memory with given alignment.
- Return
A pointer to the allocated region, or nullptr.
- Parameters
size
: The size of the memory to allocate.alignment
: The alignment of the allocation.
-
auto
free
(void *ptr) noexcept -> void¶ Frees the memory pointed to by ptr.
- Parameters
ptr
: The pointer to the memory to free.
-
auto
free
(void *ptr, size_t size) noexcept -> void¶ Frees the memory pointed to by the pointer.
- Parameters
ptr
: The pointer to the memory to free.size
: The size of the memory to free.
-
auto
reset
() noexcept -> void¶ Resets the primary and fallback allocators.
-
template<typename
T
, typename ...Args
>
autocreate
(Args&&... args) noexcept -> T*¶ Allocates and constructs an object of type T.
If this is used, then destroy should be used to destruct and free the object, rather than free.
- Return
A pointer to the created object, or a nullptr.
- Parameters
args
: The arguments for constructing the objects.
- Template Parameters
T
: The type of the object to allocate.Args
: The types of the arguments for constructing T.