slang::BumpAllocator class

BumpAllocator - Fast O(1) allocator.

Allocates items sequentially in memory, with underlying memory allocated in blocks as needed. Individual items cannot be deallocated; the entire thing must be destroyed to release the memory.

Derived classes

template<typename T>
class TypedBumpAllocator
A strongly-typed version of the BumpAllocator, which has the additional behavior of calling destructors on all elements when the allocator itself is destructed.
template<typename T>
class TypedBumpAllocator
A strongly-typed version of the BumpAllocator, which has the additional behavior of calling destructors on all elements when the allocator itself is destructed.
template<typename T>
class TypedBumpAllocator
A strongly-typed version of the BumpAllocator, which has the additional behavior of calling destructors on all elements when the allocator itself is destructed.
template<typename T>
class TypedBumpAllocator
A strongly-typed version of the BumpAllocator, which has the additional behavior of calling destructors on all elements when the allocator itself is destructed.
template<typename T>
class TypedBumpAllocator
A strongly-typed version of the BumpAllocator, which has the additional behavior of calling destructors on all elements when the allocator itself is destructed.
template<typename T>
class TypedBumpAllocator
A strongly-typed version of the BumpAllocator, which has the additional behavior of calling destructors on all elements when the allocator itself is destructed.
template<typename T>
class TypedBumpAllocator
A strongly-typed version of the BumpAllocator, which has the additional behavior of calling destructors on all elements when the allocator itself is destructed.
template<typename T>
class TypedBumpAllocator
A strongly-typed version of the BumpAllocator, which has the additional behavior of calling destructors on all elements when the allocator itself is destructed.
template<typename T>
class TypedBumpAllocator
A strongly-typed version of the BumpAllocator, which has the additional behavior of calling destructors on all elements when the allocator itself is destructed.
class Compilation
A centralized location for creating and caching symbols.

Public functions

template<typename T, typename... Args>
auto emplace(Args && ... args) -> T*
Construct a new item using the allocator.
auto allocate(size_t size, size_t alignment) -> byte*
Allocate size bytes of memory with the given alignment.
template<typename T>
auto copyFrom(std::span<const T> src) -> std::span<T>
Copies the contents of the given span into a new memory region allocated and owned by this allocator and returns a span pointing to it.
void steal(BumpAllocator&& other)
Steals ownership of all of the memory contents of the given allocator.
void freeze()
Freeze the allocator, preventing further allocations.
void unfreeze()
Unfreeze the allocator, allowing further allocations.
auto isFrozen() const -> bool
Returns true if the allocator is frozen, and false otherwise.

Function documentation

template<typename T, typename... Args>
T* slang::BumpAllocator::emplace(Args && ... args)

Construct a new item using the allocator.

NOTE: the type of object being created must be trivially destructible, since the allocator won't run destructors when freeing memory.

void slang::BumpAllocator::steal(BumpAllocator&& other)

Steals ownership of all of the memory contents of the given allocator.

The other allocator will be in a moved-from state after the call.

void slang::BumpAllocator::freeze()

Freeze the allocator, preventing further allocations.

Attempts to allocate after freezing will assert.