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 fn allocate_zeroed(
&self,
layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
pub fn allocate_zeroed( &self, layout: Layout ) -> Result<NonNull<[u8]>, AllocError>
Behaves like allocate
, but also ensures that the returned memory is zero-initialized.
sourcepub unsafe fn resize(
&self,
ptr: NonNull<u8>,
old_size: usize,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
pub unsafe fn resize( &self, ptr: NonNull<u8>, old_size: usize, 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 resize_zeroed(
&self,
ptr: NonNull<u8>,
old_size: usize,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
pub unsafe fn resize_zeroed( &self, ptr: NonNull<u8>, old_size: usize, new_layout: Layout ) -> Result<NonNull<[u8]>, AllocError>
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
.
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§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 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>
allocator_api
)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>
allocator_api
)grow
, but also ensures that the new contents are set to zero before being
returned. 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§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 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>
allocator_api
)grow
, but also ensures that the new contents are set to zero before being
returned. Read more