pub struct Bump { /* private fields */ }Expand description
A thread-safe bump allocator that provides Sync + Send semantics.
Each thread gets its own BumpLocal instance.
Implementations§
Source§impl Bump
impl Bump
Sourcepub fn builder() -> BumpBuilder
pub fn builder() -> BumpBuilder
Returns a BumpBuilder for configuring a Bump allocator.
§Examples
use bump_local::Bump;
let bump = Bump::builder()
.threads_capacity(8)
.bump_capacity(4096)
.build();Sourcepub fn reset_all(&mut self) -> Result<(), ResetError>
pub fn reset_all(&mut self) -> Result<(), ResetError>
Resets all threads’ bump allocators, deallocating all previously allocated memory.
§Safety Contract
- At the moment of reset it must be the only handle to the
Bump. - Like
bumpalo::Bump::reset(), callers must ensure no references to allocated memory are used after calling this method. - This does not run any
Dropimplementations.
Trait Implementations§
Source§impl Allocator for Bump
impl Allocator for Bump
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to allocate a block of memory. Read more
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
🔬This is a nightly-only experimental API. (
allocator_api)Deallocates the memory referenced by
ptr. Read moreSource§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to shrink the memory block. Read more
Source§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to extend the memory block. Read more
Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Behaves like
grow, but also ensures that the new contents are set to zero before being
returned. Read moreSource§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Behaves like
allocate, but also ensures that the returned memory is zero-initialized. Read moreAuto Trait Implementations§
impl Freeze for Bump
impl RefUnwindSafe for Bump
impl Send for Bump
impl Sync for Bump
impl Unpin for Bump
impl UnwindSafe for Bump
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more