[−][src]Struct bulk_allocator::LayoutBulkA
'LayoutBulkA' stands for 'single-Layout-cache Bulk Allocator'.
This implements GlobalAlloc . It allocates and caches bulk memory from the backend, and
deallocates them on the drop at once.
Constructor takes a Layout as the argument, and builds instance with cache for memories which
fits the Layout .
Method alloc delegates the request to the backend allocator if specified Layout is
different from that is passed to the constructor.
Otherwise, alloc searches the cache for an available pointer and returns it. If the cache is
empty, alloc allocates a memory chunk from the backend allocator, splits the chunk into
pieces to fit the Layout , and makes cache at first.
The size of the bulk memory is usualy same to MEMORY_CHUNK_SIZE , however, if the Layout
is too large, the size exceeds MEMORY_CHUNK_SIZE .
Method dealloc delegates the request to the backend allocator if specified Layout is
different from that is passed to the constructor; otherwise dealloc caches the pointer. i.e.
the memory will not be freed then. It is when the instance is dropped to deallocate the
memories.
Instance drop releases all the memory chunks using the backend allocator. Pointers allocated
via the instance will be invalid after the instance drop if the argument Layout is same
between the constructor and method alloc . Accessing such a pointer may lead memory unsafety
even if the pointer itself is not deallocated.
This struct is similar to UnLayoutBulkA except for the behavior when alloc and dealloc
was passed different argument Layout from that is passed to the constructor. See also
UnLayoutBulkA .
Warnings
Pointers allocated vir the instance will be invalid after the instance drop if the argument
Layout is same between the constructor and method alloc . Accessing such a pointer may lead
memory unsafety even if the pointer itself is not deallocated.
Implementations
impl<B> LayoutBulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
pub fn new(layout: Layout, backend: B) -> Self[src]
Creates a new instance with empty cache.
The cache is built for memories to fit layout and method alloc uses the cache only when
the same layout is passed; otherwise alloc just delegates the request to the backend.
backend is an allocator to allocate memory chunks to make cache. It is also used to
deallocate the memory chunks on the drop.
Examples
use bulk_allocator::LayoutBulkA; use std::alloc::{Layout, System}; let layout = Layout::new::<usize>(); let _alloc = LayoutBulkA::new(layout, System);
impl<B> LayoutBulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
pub fn layout(&self) -> Layout[src]
Returns same Layout that is passed to the constructor.
The cache is build for this Layout and method alloc can take only this value as the
argument; otherwise alloc causes an assertion error.
Examples
use bulk_allocator::LayoutBulkA; use std::alloc::{Layout, System}; let layout = Layout::new::<usize>(); let alloc = LayoutBulkA::new(layout, System); assert_eq!(layout, alloc.layout());
pub fn backend(&self) -> &B[src]
Provides a reference to the backend allocator.
Trait Implementations
impl<B> From<Layout> for LayoutBulkA<B> where
B: Default + GlobalAlloc, [src]
B: Default + GlobalAlloc,
impl<B> GlobalAlloc for LayoutBulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
Auto Trait Implementations
impl<B> !RefUnwindSafe for LayoutBulkA<B>
impl<B> Send for LayoutBulkA<B> where
B: Send,
B: Send,
impl<B> !Sync for LayoutBulkA<B>
impl<B> Unpin for LayoutBulkA<B> where
B: Unpin,
B: Unpin,
impl<B> UnwindSafe for LayoutBulkA<B> where
B: UnwindSafe,
B: UnwindSafe,
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,
pub 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.
pub 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>,