[−][src]Struct bulk_allocator::BulkA
'BulkA' stands for '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 and dealloc just delegate the requests to the backend if specified Layout
does not satisfied the condition.
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 caches the passed pointer if specified Layout is cacheable.
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 this instance will be invalid after the instance drop if the Layout is cacheable.
Accessing such a pointer may lead memory unsafety even if the pointer itself is not
deallocated.
Warnings
Pointers via this instance will be invalid after the instance drop if the Layout is
cacheable.
Accessing such a pointer may lead memory unsafety even if the pointer itself is not
deallocated.
Implementations
impl<B> BulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
pub const MAX_LAYOUT_SIZE: usize[src]
The max size of the Layout that method alloc uses the cache.
Method alloc delegates the request to the backend if the size of specified Layout is
greater than this value.
pub const MAX_LAYOUT_ALIGN: usize[src]
The max layout of the Layout that method alloc uses the cache.
Method dealloc delegates the request to the backend if the size of specified Layout is
greater than this value.
(Actually, the align of Layout usually equals to or less than this number except for that
the programer dares to set some greater value for some reason.)
impl<B> BulkA<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::BulkA; use std::alloc::System; let _alloc = BulkA::new(System);
impl<B> BulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
Trait Implementations
impl<B> GlobalAlloc for BulkA<B> where
B: GlobalAlloc, [src]
B: GlobalAlloc,
Auto Trait Implementations
impl<B> !RefUnwindSafe for BulkA<B>
impl<B> Send for BulkA<B> where
B: Send,
B: Send,
impl<B> !Sync for BulkA<B>
impl<B> Unpin for BulkA<B> where
B: Unpin,
B: Unpin,
impl<B> UnwindSafe for BulkA<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>,