Expand description
Contains types to configure bump allocation.
You can configure various settings of the bump allocator:
-
MIN_ALIGNdefault: 1 — The alignment the bump pointer maintains when doing allocations.When allocating a type in a bump allocator with a sufficient minimum alignment, the bump pointer will not have to be aligned for the allocation but the allocation size will need to be rounded up to the next multiple of the minimum alignment.
For the performance impact see crates/callgrind-benches.
-
UPdefault: true — Controls the bump direction.Bumping upwards has the advantage that the most recent allocation can be grown and shrunk in place. This benefits collections as well as
alloc_iter(_mut)andalloc_fmt(_mut)with the exception ofMutBumpVecRevandalloc_iter_mut_revwhich can be grown and shrunk in place if and only if bumping downwards.Bumping downwards can be done in less instructions.
For the performance impact see crates/callgrind-benches.
-
GUARANTEED_ALLOCATEDdefault: true — Whether at least one chunk has been allocated.The
unallocatedconstructor will create a bump allocator without allocating a chunk. It will only compile whenGUARANTEED_ALLOCATEDisfalse.The constructors
new(_in),default,with_size(_in)andwith_capacity(_in)will allocate a chunk and are always available.Setting
GUARANTEED_ALLOCATEDtofalseadds additional checks and code paths for handling the no-chunk-allocated state when callingreset_to, exiting scopes or callingby_value. -
CLAIMABLEdefault: true — Enables theclaimapi.When this is
false, callingclaimwill fail to compile. -
DEALLOCATESdefault: true — Toggles deallocation.When this is
false,Allocator::deallocatedoes nothing. -
SHRINKSdefault: true — Toggles shrinking.When this is
false,Allocator::shrinkandBumpAllocatorTyped::shrink_slicedo nothing1.This also affects the temporary collections used in
alloc_iter,alloc_fmt, etc. -
MINIMUM_CHUNK_SIZEdefault: 512 — Configures the minimum chunk size.The final chunk size is calculated like described in
with_size, thus it can be slightly smaller than requested.
§Example
You can configure the allocator settings using BumpSettings:
use bump_scope::{ Bump, alloc::Global, settings::BumpSettings };
type MyBumpSettings = BumpSettings<
/* MIN_ALIGN */ 8,
/* UP */ false,
/* GUARANTEED_ALLOCATED */ true,
/* CLAIMABLE */ false,
/* DEALLOCATES */ false,
/* SHRINKS */ false,
/* MINIMUM_CHUNK_SIZE */ 4096,
>;
type MyBump = Bump<Global, MyBumpSettings>;
let bump = MyBump::with_size(0);
assert_eq!(bump.stats().size(), 4096 - size_of::<[usize; 2]>());
bump.alloc_str("Hello, world!");Calling
shrinkwith a new layout of a greater alignment does still shift bytes around and may cause an allocation. ↩
Structs§
- Bool
- Used to create
TrueandFalsetypes. - Bump
Settings - Implementor of
BumpAllocatorSettings. - Minimum
Alignment - Specifies the current minimum alignment of a bump allocator.
Traits§
- Boolean
- Either
TrueorFalse. - Bump
Allocator Settings - The trait powering bump allocator configuration.
- Supported
Minimum Alignment - Statically guarantees that a minimum alignment is supported.