pub struct LocalBlinkAlloc<'a, A: Allocator = Global> { /* private fields */ }
Expand description

Thread-local proxy for SyncBlinkAlloc.

Using proxy can yield better performance when it is possible to create proxy once to use for many allocations.

See SyncBlinkAlloc::local for more details.

Implementations§

source§

impl<A> LocalBlinkAlloc<'_, A>where A: Allocator,

source

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

Allocates memory with specified layout from this allocator. If needed it will allocate new chunk using underlying allocator. If chunk allocation fails, it will return Err.

source

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

Resizes memory allocation. Potentially happens in-place.

Safety

ptr must be a pointer previously returned by allocate. old_size must be in range layout.size()..=slice.len() where layout is the layout used in the call to allocate. and slice is the slice pointer returned by allocate.

On success, the old pointer is invalidated and the new pointer is returned. On error old allocation is still valid.

source

pub unsafe fn deallocate(&self, ptr: NonNull<u8>, size: usize)

Deallocates memory previously allocated from this allocator.

This call may not actually free memory. All memory is guaranteed to be freed on reset call.

Safety

ptr must be a pointer previously returned by allocate. size must be in range layout.size()..=slice.len() where layout is the layout used in the call to allocate. and slice is the slice pointer returned by allocate.

source

pub fn reset(&mut self)

Resets this allocator, deallocating all chunks except the last one. Last chunk will be reused. With steady memory usage after few iterations one chunk should be sufficient for all allocations between resets.

source

pub unsafe fn reset_unchecked(&self)

Resets this allocator, deallocating all chunks except the last one. Last chunk will be reused. With steady memory usage after few iterations one chunk should be sufficient for all allocations between resets.

Safety

Blink-allocators guarantee that memory can be used while shared borrow to the allocator is held, preventing safe fn reset call.

With this method it becomes caller responsibility to ensure that allocated memory won’t be used after reset.

Trait Implementations§

source§

impl<A> Allocator for &mut LocalBlinkAlloc<'_, A>where A: Allocator,

source§

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§

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 more
source§

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>

🔬This is a nightly-only experimental API. (allocator_api)
Attempts to extend the memory block. Read more
source§

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 more
source§

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 more
source§

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

🔬This is a nightly-only experimental API. (allocator_api)
Creates a “by reference” adapter for this instance of Allocator. Read more
source§

impl<A> Allocator for LocalBlinkAlloc<'_, A>where A: Allocator,

source§

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 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>

🔬This is a nightly-only experimental API. (allocator_api)
Attempts to extend the memory block. Read more
source§

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 more
source§

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 more
source§

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 more
source§

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

🔬This is a nightly-only experimental API. (allocator_api)
Creates a “by reference” adapter for this instance of Allocator. Read more
source§

impl<A> BlinkAllocator for LocalBlinkAlloc<'_, A>where A: Allocator,

source§

fn reset(&mut self)

Resets allocator potentially invalidating all allocations made from this instance. This is no-op if allocator is Clone (typically shared reference to blink-allocator). Read more
source§

impl<A> Drop for LocalBlinkAlloc<'_, A>where A: Allocator,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, A = Global> !RefUnwindSafe for LocalBlinkAlloc<'a, A>

§

impl<'a, A> Send for LocalBlinkAlloc<'a, A>where A: Sync,

§

impl<'a, A = Global> !Sync for LocalBlinkAlloc<'a, A>

§

impl<'a, A> Unpin for LocalBlinkAlloc<'a, A>

§

impl<'a, A = Global> !UnwindSafe for LocalBlinkAlloc<'a, 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, 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.