pub struct Allocator(/* private fields */);Expand description
An allocator.
Implementations§
Source§impl Allocator
impl Allocator
Sourcepub const unsafe fn new() -> Self
pub const unsafe fn new() -> Self
Creates an allocator.
§Safety
The allocator must be used only in a main thread or threads registered to a collector, and its memory blocks must not be referenced only from memory the collector does not scan, such as memory of other allocators.
Sourcepub unsafe fn initialize()
pub unsafe fn initialize()
Sourcepub unsafe fn register_current_thread() -> Result<ThreadRegistration, Error>
pub unsafe fn register_current_thread() -> Result<ThreadRegistration, Error>
Registers a current thread to a collector.
§Safety
A collector must be initialized already, and a pointer into it held by the thread must be handed off to another thread before the registration is dropped.
Sourcepub unsafe fn set_stack_bottom(bottom: *const u8)
pub unsafe fn set_stack_bottom(bottom: *const u8)
Sets a bottom of a stack.
You do not have to call this function in most cases. A collector detects the bottom on initialization automatically.
§Safety
The bottom address must be valid.
Sourcepub fn force_collect()
pub fn force_collect()
Runs a garbage collection forcibly.
Trait Implementations§
Source§impl Allocator for Allocator
impl Allocator for Allocator
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Attempts to allocate a block of memory. Read more
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
Deallocates the memory referenced by
ptr. Read more1.100.0 (const: unstable) · Source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Behaves like
allocate, but also ensures that the returned memory is zero-initialized. Read more1.100.0 (const: unstable) · Source§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Attempts to extend the memory block. Read more
impl Copy for Allocator
Source§impl GlobalAlloc for Allocator
impl GlobalAlloc for Allocator
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocates memory as described by the given
layout. Read moreAuto Trait Implementations§
impl Freeze for Allocator
impl RefUnwindSafe for Allocator
impl Send for Allocator
impl Sync for Allocator
impl Unpin for Allocator
impl UnsafeUnpin for Allocator
impl UnwindSafe for Allocator
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