pub struct Locked<A> { /* private fields */ }
Expand description
A wrapper around a spin::Mutex
to provide safe, locked access to the inner allocator.
The Locked
type ensures that only one thread can access the allocator at a time.
Implementations§
Trait Implementations§
Source§impl GlobalAlloc for Locked<BumpAllocator>
impl GlobalAlloc for Locked<BumpAllocator>
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocates a memory block with the specified layout.
§Safety
This function must be used in a single-threaded environment or protected by a lock.
Source§unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout)
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout)
Deallocates a memory block. Since this is a bump allocator, deallocation is only meaningful when all allocations are freed at once.
§Safety
The provided pointer must be valid and previously allocated.
1.28.0§unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
alloc
, but also ensures that the contents
are set to zero before being returned. Read moreSource§impl GlobalAlloc for Locked<FixedSizeBlockAllocator>
impl GlobalAlloc for Locked<FixedSizeBlockAllocator>
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocates memory with the requested layout.
§Safety
This function must be called only in a thread-safe context.
Source§unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
Deallocates memory and inserts it back into the free list if applicable.
§Safety
The provided pointer must be valid and previously allocated.
1.28.0§unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
alloc
, but also ensures that the contents
are set to zero before being returned. Read moreSource§impl GlobalAlloc for Locked<LinkedListAllocator>
Implements the global allocator trait for LinkedListAllocator
.
impl GlobalAlloc for Locked<LinkedListAllocator>
Implements the global allocator trait for LinkedListAllocator
.
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocates a memory block with the given layout.
§Safety
The caller must ensure that the requested allocation is valid and does not cause undefined behavior.
Source§unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)
Deallocates a previously allocated memory block.
§Safety
The caller must ensure that the pointer and layout are valid and that the memory block was allocated by this allocator.
1.28.0§unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
alloc
, but also ensures that the contents
are set to zero before being returned. Read more