Shortcuts

Class LinearAllocator

Class Documentation

class ripple::LinearAllocator

This allocator allocates data linearly from a provided arena.

While it provides an interface for freeing an individual element, it’s an empty function, and the allocator only allows resetting all allocations from the pool. It just bumps along the pointer to the next allocation address. It can allocate different sizes.

Public Functions

LinearAllocator(void *begin, void *end) noexcept

Constructor to set the begin and end of the available memory for the allocator.

Parameters
  • begin: The start of the allocation arena.

  • end: The end of the allocation arena.

template<typename Arena>
LinearAllocator(const Arena &arena) noexcept

Constructor which takes an Arena which defines the regions from which the allocator can allocate.

Parameters
  • arena: The area to allocate memory from.

Template Parameters
  • Arena: The type of the arena.

~LinearAllocator() noexcept

Defstructor resets the memory if the pointer is not null.

LinearAllocator(LinearAllocator &&other) noexcept

Move construcor, swaps the other allocator with this one.

Parameters
  • other: The other allocator to create this one from.

auto operator=(LinearAllocator &&other) noexcept -> LinearAllocator&

Move assignment, swaps the other allocator with this one.

Return

The newly constructed allocator.

Parameters
  • other: The other allocator to swap with this one.

LinearAllocator(const LinearAllocator&) = delete

Copy constructor deleted.

auto operator=(const LinearAllocator&) = delete

Copy assignment deleted.

auto alloc(size_t size, size_t alignment) noexcept -> void*

Allocates the given number of bytes with the given alignment.

Return

A valid pointer if the allocation succeeded, otherwise a nullptr.

Parameters
  • size: The number of bytes to allocate.

  • alignment: The alignment for the allocation.

auto free(void *ptr) noexcept -> void

This does not free the ptr, since it does not allow freeing of individual allocations.

This allocator only allows resetting.

Note

This is provided so that the allocator has the same interface as other allocators.

Parameters
  • ptr: The pointer to free.

auto free(void *ptr, size_t size) noexcept -> void

This does not free the ptr, since it does not allow freeing of individual allocations.

This allocator only allows resetting.

Note

This is provided so that the allocator has the same interface as other allocators.

Parameters
  • ptr: The pointer to free.

  • size: The size to free.

auto capacity() noexcept -> size_t

Gets the amount of allocation space remaining in the allocator.

Return

The amount of allocation space remaining in the allocator.

auto reset(void *begin = nullptr, void *end = nullptr) noexcept -> void

Resets the allocator to the begining of the allocation arena.

This invalidates any allocations from the allocator, since any subsequent allocations will overwrite old allocations.

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