[][src]Struct bulk_allocator::UnBulkA

pub struct UnBulkA<B> where
    B: GlobalAlloc
{ /* fields omitted */ }

'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]

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]

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]

pub fn backend(&self) -> &B[src]

Provides a reference to the backend allocator.

Trait Implementations

impl<B> Default for UnBulkA<B> where
    B: Default + GlobalAlloc
[src]

impl<B> Drop for UnBulkA<B> where
    B: GlobalAlloc
[src]

impl<B> GlobalAlloc for UnBulkA<B> where
    B: GlobalAlloc
[src]

impl<B> Send for UnBulkA<B> where
    B: Send + GlobalAlloc
[src]

Auto Trait Implementations

impl<B> !RefUnwindSafe for UnBulkA<B>

impl<B> !Sync for UnBulkA<B>

impl<B> Unpin for UnBulkA<B> where
    B: Unpin

impl<B> UnwindSafe for UnBulkA<B> where
    B: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.