Shortcuts

Template Class Allocator

Class Documentation

template<typename PrimaryAllocator, typename Arena, typename FallbackAllocator, typename LockingPolicy>
class ripple::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.

Allocator(const Allocator&) = delete

Copy constructor deleted, allocator can’t be copied.

auto operator=(const Allocator&) = delete

Copy assignment deleted, allocator can’t be copied.

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>
auto create(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.

template<typename T>
auto recycle(T *ptr) noexcept -> void

Recycles the pointed to object, destructing it and then releasing the memory back to the allocator.

Parameters
  • ptr: A pointer to the object to destroy.

Template Parameters
  • T: The type of the object.

Public Static Attributes

constexpr bool contexpr_arena_size = Arena::constexpr_size

Returns true if the arena has a contexpr size.

Docs

Access comprehensive developer documentation for Ripple

View Docs

Tutorials

Get tutorials to help with understand all features

View Tutorials

Examples

Find examples to help get started

View Examples