pub struct SyncBumpArena { /* private fields */ }Expand description
A thread-safe bump arena allocator implementing allocator-api2’s
Allocator trait.
Holds an Arc<Mutex<SyncBumpInner>> so it is Clone + Send + Sync + 'static.
All clones share the same arena — when the last clone drops, all memory is
freed at once (the chunks’ Vec drop returns memory to the global allocator).
See the module-level documentation for the full design rationale and safety model.
Implementations§
Source§impl SyncBumpArena
impl SyncBumpArena
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new SyncBumpArena with no initial capacity.
The first allocation will trigger a 4 KiB chunk allocation.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new SyncBumpArena with an initial chunk of the given size.
This avoids a growth step on the first allocations if the approximate total size is known in advance.
Trait Implementations§
Source§impl Allocator for SyncBumpArena
impl Allocator for SyncBumpArena
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
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)
Deallocates the memory referenced by
ptr. Read moreSource§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Behaves like
allocate, but also ensures that the returned memory is zero-initialized. Read moreSource§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>
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>
Behaves like
grow, but also ensures that the new contents are set to zero before being
returned. Read moreSource§impl Clone for SyncBumpArena
impl Clone for SyncBumpArena
Source§fn clone(&self) -> SyncBumpArena
fn clone(&self) -> SyncBumpArena
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SyncBumpArena
impl Debug for SyncBumpArena
Auto Trait Implementations§
impl Freeze for SyncBumpArena
impl RefUnwindSafe for SyncBumpArena
impl Send for SyncBumpArena
impl Sync for SyncBumpArena
impl Unpin for SyncBumpArena
impl UnsafeUnpin for SyncBumpArena
impl UnwindSafe for SyncBumpArena
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