pub struct SystemAllocator;Expand description
An Allocator that delegates directly to the operating system.
SystemAllocator is a zero-sized type; it holds no state and is safe to
share across threads. It is the typical backing allocator for arena,
pool, and bump allocators when running on a hosted OS.
§Platform Notes
- Unix — Uses
posix_memalignto satisfy arbitrary alignment requests. The effective alignment is always at leastsizeof(void*)(usually 8 or 16 bytes) becauseposix_memalignrequires it. - Windows — Uses
_aligned_malloc/_aligned_free. The effective alignment is at leastsizeof(void*). - Other —
allocalways returnsNone.
Trait Implementations§
Source§impl Allocator for SystemAllocator
impl Allocator for SystemAllocator
Source§unsafe fn alloc(&self, layout: Layout) -> Option<NonNull<u8>>
unsafe fn alloc(&self, layout: Layout) -> Option<NonNull<u8>>
Allocates a block of memory according to layout.
Returns Some(ptr) where ptr is aligned to at least layout.align()
and valid for layout.size() bytes. Returns None if the OS call
fails or if the target platform is unsupported.
§Safety
layout.size()must be greater than zero; zero-sized allocations are rejected byposix_memalignand_aligned_malloc.- The returned pointer must eventually be passed to
deallocwith the samelayout.
Source§unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)
Releases a block previously allocated by this SystemAllocator.
§Safety
ptrmust have been returned by a prior successful call toallocon this sameSystemAllocator.layoutmust exactly match the layout passed to thatalloccall.- After
deallocreturns,ptris invalid and must not be accessed. - Calling
dealloctwice for the same pointer is undefined behaviour.
Auto Trait Implementations§
impl Freeze for SystemAllocator
impl RefUnwindSafe for SystemAllocator
impl Send for SystemAllocator
impl Sync for SystemAllocator
impl Unpin for SystemAllocator
impl UnsafeUnpin for SystemAllocator
impl UnwindSafe for SystemAllocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more