Struct System
struct System
The default memory allocator provided by the operating system.
This is based on malloc on Unix platforms and HeapAlloc on Windows,
plus related functions. However, it is not valid to mix use of the backing
system allocator with System, as this implementation may include extra
work, such as to serve alignment requests greater than the alignment
provided directly by the backing system allocator.
This type implements the GlobalAlloc trait. Currently the default
global allocator is unspecified. Libraries, however, like cdylibs and
staticlibs are guaranteed to use the System by default and as such
work as if they had this definition:
use System;
static A: System = System;
You can also define your own wrapper around System if you'd like, such as
keeping track of the number of all bytes allocated:
use ;
use ;
;
static ALLOCATED: AtomicUsize = new;
unsafe
static A: Counter = Counter;
It can also be used directly to allocate memory independently of whatever
global allocator has been selected for a Rust program. For example if a Rust
program opts in to using jemalloc as the global allocator, System will
still allocate memory using malloc and HeapAlloc.
Implementations
impl Allocator for System
fn allocate(self: &Self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>fn allocate_zeroed(self: &Self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>unsafe fn deallocate(self: &Self, ptr: NonNull<u8>, layout: Layout)unsafe fn grow(self: &Self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout) -> Result<NonNull<[u8]>, AllocError>unsafe fn grow_zeroed(self: &Self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout) -> Result<NonNull<[u8]>, AllocError>unsafe fn shrink(self: &Self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout) -> Result<NonNull<[u8]>, AllocError>
impl Clone for System
fn clone(self: &Self) -> System
impl Copy for System
impl Debug for System
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Default for System
fn default() -> System
impl Freeze for System
impl GlobalAlloc for crate::alloc::System
unsafe fn alloc(self: &Self, layout: Layout) -> *mut u8unsafe fn alloc_zeroed(self: &Self, layout: Layout) -> *mut u8unsafe fn dealloc(self: &Self, ptr: *mut u8, _layout: Layout)unsafe fn realloc(self: &Self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
impl RefUnwindSafe for System
impl Send for System
impl Sync for System
impl Unpin for System
impl UnwindSafe for System
impl<T> Any for System
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for System
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for System
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for System
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for System
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for System
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for System
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for System
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for System
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>