pub struct UnsafeLayoutBulkAlloc<B = System>where
    B: GlobalAlloc,{ /* private fields */ }
Expand description

UnsafeLayoutBulkAlloc is an implementation of GlobalAlloc.

Each instance manages a cache for a specific layout and releases all of them on the drop at once.

Method alloc dispatches and returns a pointer from the cache, while dealloc stores the passed pointer in the cache.

See alloc and dealloc for the details.

In order to ensure effective caching, it is imperative that Layout remains consistently the same, or else panics. (This is why the term “Unsafe” is employed.) To cache effectively, Layout must be always same, or panics. Consequently, method realloc always panics.

See realloc for the details.

Safety

Instance drop releases all the memory, and all the pointers allocated via the instance will be invalid after then. Accessing such a pointer may lead to memory unsafety even if the pointer itself is not deallocated.

Implementations§

source§

impl<B> UnsafeLayoutBulkAlloc<B>where B: GlobalAlloc,

source

pub const fn new(backend: B) -> Self

Creates a new instance.

Trait Implementations§

source§

impl<B> Default for UnsafeLayoutBulkAlloc<B>where B: GlobalAlloc + Default,

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<B> Drop for UnsafeLayoutBulkAlloc<B>where B: GlobalAlloc,

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<B> GlobalAlloc for UnsafeLayoutBulkAlloc<B>where B: GlobalAlloc,

source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

alloc rounds up the size of layout to a multiple of the alignment of that.

This method panics if this is not the first method call and if the rounded-up layout is different from that of the first call.

If the rounded-up layout is OK, alloc allocates and caches a memory chunk via the backend if the cache is empty, and dispatches a pointer from the cache to return.

read more

Safety

Instance drop releases all the memory, and all the pointers allocated via the instance will be invalid after then. Accessing such a pointer may lead to memory unsafety even if the pointer itself is not deallocated.

Panics

Panics if the method call is not the first time, and if the rounded-up layout is different from that of the first call.

source§

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

delloc rounds up the size of layout to a multiple of the alignment of that.

Otherwise, dealloc stores the passed pointer into the cache. i.e. this method does not release the memory immediately. It is when the object is dropped to free the memory.

read more

Panics

If the rounded-up layout is different from that passed to alloc.

source§

unsafe fn realloc(&self, _: *mut u8, _: Layout, _: usize) -> *mut u8

Panics if called.

read more

1.28.0 · source§

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8

Behaves like alloc, but also ensures that the contents are set to zero before being returned. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.