Struct blink_alloc::LocalBlinkAlloc
source · 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,
impl<A> LocalBlinkAlloc<'_, A>where A: Allocator,
sourcepub fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
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
.
sourcepub unsafe fn resize(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
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.
sourcepub unsafe fn deallocate(&self, ptr: NonNull<u8>, size: usize)
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
.
sourcepub fn reset(&mut self)
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.
sourcepub unsafe fn reset_unchecked(&self)
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,
impl<A> Allocator for &mut LocalBlinkAlloc<'_, A>where A: Allocator,
source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)allocate
, but also ensures that the returned memory is zero-initialized. Read moresource§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout ) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)source§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>
allocator_api
)source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
allocator_api
)ptr
. Read moresource§impl<A> Allocator for LocalBlinkAlloc<'_, A>where
A: Allocator,
impl<A> Allocator for LocalBlinkAlloc<'_, A>where A: Allocator,
source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)source§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout ) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)source§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>
allocator_api
)source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
allocator_api
)ptr
. Read moresource§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)allocate
, but also ensures that the returned memory is zero-initialized. Read more