pub struct SharedArena<A: Allocator = Global>(/* private fields */);Expand description
A thread-safe bump arena (Send + Sync).
Share &SharedArena across threads (for example, one arena for a whole
parallel compilation); every worker allocates into it and the results live for
the shared borrow. For contention-free per-worker scratch, take a
ScopedArena with scoped.
Implementations§
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates new arena allocator that uses global allocator to allocate memory chunks.
See SharedArena::new_in for using custom allocator.
Sourcepub const fn with_chunk_size(chunk_size: usize) -> Self
pub const fn with_chunk_size(chunk_size: usize) -> Self
Creates new arena allocator that uses global allocator to allocate memory chunks. With this method you can specify initial chunk size.
See SharedArena::new_in for using custom allocator.
Sourcepub const fn new_in(arena: A) -> Self
pub const fn new_in(arena: A) -> Self
Creates new arena allocator that uses the given allocator to allocate memory chunks.
Sourcepub const fn with_chunk_size_in(chunk_size: usize, arena: A) -> Self
pub const fn with_chunk_size_in(chunk_size: usize, arena: A) -> Self
Creates a new, empty arena whose chunks are at least chunk_size bytes.
Sourcepub fn scoped(&self) -> ScopedArena<'_, A>
pub fn scoped(&self) -> ScopedArena<'_, A>
Returns a thread-local ScopedArena drawing from this arena.
Each worker in a parallel pass can take its own scope and allocate scratch without contending on the shared bump pointer.
Trait Implementations§
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocate, but also ensures that the returned memory is zero-initialized. Read moreSource§unsafe fn deallocate(&self, pointer: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, pointer: NonNull<u8>, layout: Layout)
ptr. Read moreSource§unsafe fn grow(
&self,
pointer: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, pointer: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Source§unsafe fn grow_zeroed(
&self,
pointer: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, pointer: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
grow, but also ensures that the new contents are set to zero before being
returned. Read moreAuto Trait Implementations§
Blanket Implementations§
Source§impl<A> Arena for A
impl<A> Arena for A
Source§fn alloc_with<T>(&self, f: impl FnOnce() -> T) -> &mut T
fn alloc_with<T>(&self, f: impl FnOnce() -> T) -> &mut T
f, evaluated directly into the arena slot.Source§fn alloc_fmt(&self, arguments: Arguments<'_>) -> &mut str
fn alloc_fmt(&self, arguments: Arguments<'_>) -> &mut str
arguments directly into the arena and returns the resulting string. Read moreSource§fn alloc_slice_copy<T>(&self, src: &[T]) -> &mut [T]where
T: Copy,
fn alloc_slice_copy<T>(&self, src: &[T]) -> &mut [T]where
T: Copy,
Copy values into the arena.Source§fn alloc_slice_clone<T>(&self, src: &[T]) -> &mut [T]where
T: Clone,
fn alloc_slice_clone<T>(&self, src: &[T]) -> &mut [T]where
T: Clone,
Clone values into the arena.Source§fn alloc_slice_fill_copy<T>(&self, len: usize, value: T) -> &mut [T]where
T: Copy,
fn alloc_slice_fill_copy<T>(&self, len: usize, value: T) -> &mut [T]where
T: Copy,
len copies of value.Source§fn alloc_slice_fill_clone<T>(&self, len: usize, value: &T) -> &mut [T]where
T: Clone,
fn alloc_slice_fill_clone<T>(&self, len: usize, value: &T) -> &mut [T]where
T: Clone,
len clones of value.Source§fn alloc_slice_fill_with<T>(
&self,
len: usize,
f: impl FnMut(usize) -> T,
) -> &mut [T]
fn alloc_slice_fill_with<T>( &self, len: usize, f: impl FnMut(usize) -> T, ) -> &mut [T]
len elements, each produced by f(index).Source§fn alloc_slice_fill_default<T>(&self, len: usize) -> &mut [T]where
T: Default,
fn alloc_slice_fill_default<T>(&self, len: usize) -> &mut [T]where
T: Default,
len default-constructed elements.Source§fn alloc_slice_fill_iter<T>(
&self,
iter: impl IntoIterator<Item = T>,
) -> &mut [T]
fn alloc_slice_fill_iter<T>( &self, iter: impl IntoIterator<Item = T>, ) -> &mut [T]
iter into the arena and returns the resulting slice.