Struct ring_alloc::RingAlloc
source · #[repr(transparent)]pub struct RingAlloc<A: Allocator = Global> { /* private fields */ }
Expand description
Thread-local ring-allocator.
This allocator uses underlying allocator to allocate memory chunks.
Allocator uses ring buffer of chunks to allocate memory in front chunk, moving it to back if chunk is full. If next chunk is still occupied by previous allocation, allocator will allocate new chunk.
Implementations§
source§impl<A> RingAlloc<A>where
A: Allocator,
impl<A> RingAlloc<A>where A: Allocator,
sourcepub fn try_new_in(allocator: A) -> Result<Self, AllocError>
pub fn try_new_in(allocator: A) -> Result<Self, AllocError>
Attempts to create new RingAlloc
that uses given allocator.
sourcepub fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
pub fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Attempts to allocate a block of memory with this ring-allocator. Returns a pointer to the beginning of the block if successful.
sourcepub unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
pub unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
Deallocates the memory referenced by ptr
.
Safety
ptr
must denote a block of memory currently allocated viaRingAlloc::allocate
, andlayout
must fit that block of memory.
Trait Implementations§
source§impl<A> Allocator for RingAlloc<A>where
A: Allocator,
impl<A> Allocator for RingAlloc<A>where A: Allocator,
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 moreAuto Trait Implementations§
impl<A = Global> !RefUnwindSafe for RingAlloc<A>
impl<A = Global> !Send for RingAlloc<A>
impl<A = Global> !Sync for RingAlloc<A>
impl<A> Unpin for RingAlloc<A>
impl<A = Global> !UnwindSafe for RingAlloc<A>
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