[−][src]Struct bulk_allocator::UnLayoutBulkA
'UnLayoutBulkA' stands for 'Unsafe 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 causes an assertion error if the specified Layout is different from that is
passed to the constructor. (This is why named as 'Unsafe'.)
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 always caches the passed 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. All the pointers allocated via the instance will be invalid after the instance drop. Accessing such a pointer may lead memory unsafety even if the pointer itself is not deallocated.
This struct is similar to LayoutBulkA except for the behavior when alloc and dealloc
was passed different argument Layout from that is passed to the constructor. See also
LayoutBulkA .
Warnings
The allocated pointers via UnLayoutBulkA will be invalid after the instance is dropped. Accessing such
a pointer may lead memory unsafety evenn if the pointer itself is not deallocated.
Errors
alloc causes an assertion error if the specified Layout is different from that is passed to
the constructor.
Implementations
impl<B> UnLayoutBulkA<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 can take same value as
the argument; otherwise alloc causes an assertion error.
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::UnLayoutBulkA; use std::alloc::{Layout, System}; let layout = Layout::new::<usize>(); let _alloc = UnLayoutBulkA::new(layout, System);
impl<B> UnLayoutBulkA<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::UnLayoutBulkA; use std::alloc::{Layout, System}; let layout = Layout::new::<usize>(); let alloc = UnLayoutBulkA::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> Drop for UnLayoutBulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
impl<B> From<Layout> for UnLayoutBulkA<B> where
B: Default + GlobalAlloc, [src]
B: Default + GlobalAlloc,
impl<B> GlobalAlloc for UnLayoutBulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
unsafe fn alloc(&self, layout: Layout) -> *mut u8[src]
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)[src]
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u81.28.0[src]
unsafe fn realloc(
&self,
ptr: *mut u8,
layout: Layout,
new_size: usize
) -> *mut u81.28.0[src]
&self,
ptr: *mut u8,
layout: Layout,
new_size: usize
) -> *mut u8
impl<B> Send for UnLayoutBulkA<B> where
B: Send + GlobalAlloc, [src]
B: Send + GlobalAlloc,
Auto Trait Implementations
impl<B> !RefUnwindSafe for UnLayoutBulkA<B>
impl<B> !Sync for UnLayoutBulkA<B>
impl<B> Unpin for UnLayoutBulkA<B> where
B: Unpin,
B: Unpin,
impl<B> UnwindSafe for UnLayoutBulkA<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>,