10 static_assert(std::is_trivially_destructible_v<T>,
"T must be trivially destructible");
15 : size(count * sizeof(T)), memory(new char[count * sizeof(T)]), next(memory) {}
24 if (std::cmp_greater_equal(next - memory, size)) {
25 throw std::bad_alloc();
30 T *
const result =
new (next) T;
38 const auto used =
static_cast<std::size_t
>(next - memory);
39 if (count == 0 || (count *
sizeof(T)) > (size - used)) {
40 throw std::bad_alloc();
45 T *
const result =
new (next) T;
46 for (std::size_t i = 1; i < count; ++i) {
47 new (next + (i *
sizeof(T))) T;
49 next += count *
sizeof(T);
bool isDeallocSupported()
Reports that per-element deallocate is not supported (false for this allocator).
T * allocate(std::size_t count)
Bump-allocates count contiguous T objects in one step; throws std::bad_alloc when fewer than count sl...
LinearAllocator & operator=(const LinearAllocator &)=delete
T * allocate()
Bump-allocates one T; throws std::bad_alloc when the arena is exhausted.
LinearAllocator(std::size_t count)
Reserves room for count objects of T from a single backing allocation.
void reset()
Rewinds the bump pointer, reclaiming every outstanding allocation in one shot.
LinearAllocator(const LinearAllocator &)=delete
void deallocate(T *)
No-op: trivial destructibility lets per-element reclamation be skipped.