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 RingAlloc

source

pub fn new() -> Self

Returns new RingAlloc that uses [Global] allocator.

source§

impl<A> RingAlloc<A>where A: Allocator,

source

pub fn new_in(allocator: A) -> Self

Returns new RingAlloc that uses given allocator.

source

pub fn try_new_in(allocator: A) -> Result<Self, AllocError>

Attempts to create new RingAlloc that uses given allocator.

source

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.

source

pub unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)

Deallocates the memory referenced by ptr.

Safety
source

pub fn flush(&self)

Free all unused chunks back to underlying allocator.

Trait Implementations§

source§

impl<A> Allocator for RingAlloc<A>where A: Allocator,

source§

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)

Deallocates the memory referenced by ptr. Read more
source§

fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>

Behaves like allocate, but also ensures that the returned memory is zero-initialized. Read more
source§

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>

Behaves like grow, but also ensures that the new contents are set to zero before being returned. Read more
source§

unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout ) -> Result<NonNull<[u8]>, AllocError>

Attempts to shrink the memory block. Read more
source§

fn by_ref(&self) -> &Selfwhere Self: Sized,

Creates a “by reference” adapter for this instance of Allocator. Read more
source§

impl<A> Clone for RingAlloc<A>where A: Allocator,

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<A> Default for RingAlloc<A>where A: Allocator + Default,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<A> Drop for RingAlloc<A>where A: Allocator,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<A> Hash for RingAlloc<A>where A: Allocator,

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<A> PartialEq<RingAlloc<A>> for RingAlloc<A>where A: Allocator,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto 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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.