pub struct Global;Expand description
The global memory allocator.
This type implements the Allocator trait by forwarding calls
to the allocator registered with the #[global_allocator] attribute
if there is one, or the std crate’s default.
Similar to alloc, dealloc, and the other global allocation functions,
the way in which calls are forwarded to the allocator registered with
#[global_allocator] is unspecified. See their safety docs for more information.
This allocator must be treated like an opaque allocator that only guarantees
the contract described in the docs of Allocator, as well as the following
things:
- All instances of
Globalare equivalent. - Allocations from
Globalare only invalidated by calls to de-/reallocating functions. If no such call is made, then the allocation will live for the rest of the program. - The global allocation functions are equivalent to the methods on
Global, except that they disallow zero-sized allocations, and implicitly ignore any returned excess size.
Note that the current implementation of Global does not take advantage of
some features of Allocator, such as zero-sized allocations (which currently always
return a dangling pointer) and overallocating.
This may change in the future. You must not rely on it for correctness!
Trait Implementations§
1.101.0 (const: unstable) · Source§impl Allocator for Global
impl Allocator for Global
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocate, but also ensures that the returned memory is zero-initialized. Read moreSource§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
ptr. Read more