[−][src]Struct bulk_allocator::UnBulkA
'UnBulkA' stands for 'Unsafe Bulk Allocator'.
This implements GlobalAlloc . It allocates and caches bulk memory from the backend, and
deallocates them on the drop at once.
The Layout to be cached is limited. size must be less than or equal to MAX_LAYOUT_SIZE
and align must be less than or equal to MAX_LAYOUT_ALIGN .
Method alloc causes an assertion error if argument Layout does not satisfy the conditions.
alloc tries to find a cached pointer and returns it if specified Layout is cacheable.
If appropriate cache is not found, tries to find a larger cache and splits it to return. (The
rest parts of the large cache will be cached again.)
If neither the appropriate nor larger cache is not found, it allocates a memory chunk from
backend, and makes a cache at first. (The size of memory chunk is same to 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.
Warnings
The allocated pointers via Usba 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 argument Layout is too large. (i.e. if Layout.size
is greater than MAX_LAYOUT_SIZE or Layout.align is greater than MAX_LAYOUT_ALIGN .
Implementations
impl<B> UnBulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
pub const MAX_LAYOUT_SIZE: usize[src]
The max size of the Layout that method alloc accepts.
If specified Layout has greater size, alloc causes an assertion error.
pub const MAX_LAYOUT_ALIGN: usize[src]
The max layout of the Layout that method alloc accepts.
If specified Layout has greater align, alloc causes an assertion error.
(Actually, the align of Layout usually equals to or less than this value except for that
the programer dares to set some greater value for some reason.)
impl<B> UnBulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
pub fn new(backend: B) -> Self[src]
Creates a new instance with empty cache.
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::UnBulkA; use std::alloc::System; let _alloc = UnBulkA::new(System);
impl<B> UnBulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
Trait Implementations
impl<B> Default for UnBulkA<B> where
B: Default + GlobalAlloc, [src]
B: Default + GlobalAlloc,
impl<B> Drop for UnBulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
impl<B> GlobalAlloc for UnBulkA<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 UnBulkA<B> where
B: Send + GlobalAlloc, [src]
B: Send + GlobalAlloc,
Auto Trait Implementations
impl<B> !RefUnwindSafe for UnBulkA<B>
impl<B> !Sync for UnBulkA<B>
impl<B> Unpin for UnBulkA<B> where
B: Unpin,
B: Unpin,
impl<B> UnwindSafe for UnBulkA<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>,