[−][src]Struct bulk_allocator::LayoutBulkAllocator
LayoutBulkAllocator pools allocated memory and frees it on the destruction.
alloc() and dealloc() delegates the request if the layout is different from
what is specified to the constructor; otherwise, dealloc() caches the passed
pointer and alloc() returns the cache. If no memory is pooled, alloc()
allocate memory chunk from the backend, and makes caches at first.
Compared to BulkAllocator the performance of LayoutBulkAllocator is better than
that of BulkAllocator as long as the argument layout of alloc() and dealloc() is
same to which is passed to the constructor.
Lifetime
Each instance owns or borrows the backend AllocRef instance. If it is borrowed, the lifetime
is limited by the reference; otherwise, the lifetime will be 'static.
Thread safety
All the mutable methods are thread unsafe.
Warnings
After drop, programer must NOT use the memories which method alloc() of this instance returned.
Implementations
impl<B> LayoutBulkAllocator<'static, B> where
B: AllocRef + Default, [src]
B: AllocRef + Default,
pub fn from_layout(layout: Layout) -> Self[src]
Constructor specifies only the layout for the instance to use the cache.
The backend AllocRef instance is created by Default::default().
The instance owns the backend, so there is no limitation for the lifetime.
impl<B: AllocRef> LayoutBulkAllocator<'static, B>[src]
pub fn from_layout_backend(layout: Layout, backend: B) -> Self[src]
Construct a new instance from the layout and the backend AllocRef instance.
The instance owns the backend, so there is no limitation of the lifetime.
impl<'a, B: 'a + AllocRef> LayoutBulkAllocator<'a, B>[src]
pub fn from_layout_mut_backend(layout: Layout, backend: &'a mut B) -> Self[src]
Construct a neww instance from the layout and the reference to the backend.
The instance just borrows the backend, so the lifetime is limited.
Trait Implementations
impl<B: AllocRef, '_> AllocRef for LayoutBulkAllocator<'_, B>[src]
Thread safety
All the methods are thread unsafe.
fn alloc(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr>[src]
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout)[src]
fn alloc_zeroed(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr>[src]
unsafe fn grow(
&mut self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocErr>[src]
&mut self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocErr>
unsafe fn grow_zeroed(
&mut self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocErr>[src]
&mut self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocErr>
unsafe fn shrink(
&mut self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocErr>[src]
&mut self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocErr>
fn by_ref(&mut self) -> &mut Self[src]
impl<B: AllocRef, '_> Drop for LayoutBulkAllocator<'_, B>[src]
Auto Trait Implementations
impl<'a, B> RefUnwindSafe for LayoutBulkAllocator<'a, B> where
B: RefUnwindSafe,
B: RefUnwindSafe,
impl<'a, B> !Send for LayoutBulkAllocator<'a, B>
impl<'a, B> !Sync for LayoutBulkAllocator<'a, B>
impl<'a, B> Unpin for LayoutBulkAllocator<'a, B> where
B: Unpin,
B: Unpin,
impl<'a, B> !UnwindSafe for LayoutBulkAllocator<'a, B>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,