Struct vulkano::memory::allocator::suballocator::BumpAllocator
source · pub struct BumpAllocator { /* private fields */ }
Expand description
A suballocator which can allocate dynamically, but can only free all allocations at once.
With bump allocation, the used up space increases linearly as allocations are made and allocations can never be freed individually, which is why this algorithm is also called linear allocation. It is also known as arena allocation.
BumpAllocator
s are best suited for very short-lived (say a few frames at best) resources that
need to be allocated often (say each frame), to really take advantage of the performance gains.
For creating long-lived allocations, FreeListAllocator
is best suited. The way you would
typically use this allocator is to have one for each frame in flight. At the start of a frame,
you reset it and allocate your resources with it. You write to the resources, render with them,
and drop them at the end of the frame.
See also the Suballocator
implementation.
Algorithm
What happens is that every time you make an allocation, you receive one with an offset corresponding to the free start within the region, and then the free start is bumped, so that following allocations wouldn’t alias it. As you can imagine, this is extremely fast, because it doesn’t need to keep a free-list. It only needs to do a few additions and comparisons. But beware, fast is about all this is. It is horribly memory inefficient when used wrong, and is very susceptible to memory leaks.
Once you know that you are done with the allocations, meaning you know they have all been
dropped, you can safely reset the allocator using the reset
method as long as the allocator
is not shared between threads. This is one of the reasons you are generally advised to use one
BumpAllocator
per thread if you can.
Efficiency
Allocation is O(1), and so is resetting the allocator (freeing all allocations).
Implementations§
Trait Implementations§
source§impl Debug for BumpAllocator
impl Debug for BumpAllocator
source§impl Suballocator for BumpAllocator
impl Suballocator for BumpAllocator
source§fn allocate(
&self,
layout: DeviceLayout,
allocation_type: AllocationType,
buffer_image_granularity: DeviceAlignment
) -> Result<Suballocation, SuballocatorError>
fn allocate( &self, layout: DeviceLayout, allocation_type: AllocationType, buffer_image_granularity: DeviceAlignment ) -> Result<Suballocation, SuballocatorError>
source§unsafe fn deallocate(&self, _suballocation: Suballocation)
unsafe fn deallocate(&self, _suballocation: Suballocation)
suballocation
. Read more