Shortcuts

Template Class PoolAllocator

Class Documentation

template<size_t ElementSize, size_t Alignment, typename FreeList = Freelist>
class ripple::PoolAllocator

Allocator to allocator 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.

Template Parameters
  • ElementSize: The byte size of the elements in the pool.

  • Alignment: The alignment for the elements.

  • FreeList: 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 and end pointers to the memory arena for the pool.

Parameters
  • start: 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&) = 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 given alignment from the pool.

Note

This will fail if size is larger than the element size for the pool or if the alignment is larger than the alignment for the pool.

Note

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.

Since the freelist doesn’t support restting, this doesn’t do anything.

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