Class LinearAllocator

Class Documentation

class wrench::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)

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

Parameters
  • arena: The area to allocate memory from.

Template Parameters
  • Arena: The type of the arena.

~LinearAllocator() noexcept = default

Constructor defaulted.

LinearAllocator(LinearAllocator &&other) noexcept

Move construcor, swaps other with this allocator.

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.

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

LinearAllocator(const LinearAllocator&) = delete

Copy constructor deleted to disable copying.

auto operator=(const LinearAllocator&) = delete

Copy assignment deleted to disable copying.

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

Allocates size bytes with alignment.

Parameters
  • size: The number of bytes to allocate.

  • alignment: The alignment for the allocation.

auto free (void *ptr) const noexcept -> void

This does not free the ptr, since it does not allow freeing of individual allocations. This allocator only allows resetting.

Parameters
  • ptr: The pointer to free.

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

This does not free the ptr, since it does not allow freeing of individual allocations. This allocator only allows resetting.

Parameters
  • ptr: The pointer to free.

  • size: The size to free.

auto reset () 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.