Struct bulk_allocator::UnsafeLayoutBulkAlloc
source · 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,
impl<B> UnsafeLayoutBulkAlloc<B>where B: GlobalAlloc,
Trait Implementations§
source§impl<B> Default for UnsafeLayoutBulkAlloc<B>where
B: GlobalAlloc + Default,
impl<B> Default for UnsafeLayoutBulkAlloc<B>where B: GlobalAlloc + Default,
source§impl<B> Drop for UnsafeLayoutBulkAlloc<B>where
B: GlobalAlloc,
impl<B> Drop for UnsafeLayoutBulkAlloc<B>where B: GlobalAlloc,
source§impl<B> GlobalAlloc for UnsafeLayoutBulkAlloc<B>where
B: GlobalAlloc,
impl<B> GlobalAlloc for UnsafeLayoutBulkAlloc<B>where B: GlobalAlloc,
source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
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.
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)
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.
Panics
If the rounded-up layout
is different from that passed to alloc
.