diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2018-05-31 20:22:59 +0200 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2018-06-11 13:48:57 -0700 |
| commit | a24924f6834ea6e5bd813d006a12aef8e5dbd5e9 (patch) | |
| tree | 8af929586f9bc74184b8682ebaa486c2a97a8dfa /src/liballoc_system | |
| parent | fd6e08a1e6bbccd00e70b23ac72dd9a9a633be30 (diff) | |
| download | rust-a24924f6834ea6e5bd813d006a12aef8e5dbd5e9.tar.gz rust-a24924f6834ea6e5bd813d006a12aef8e5dbd5e9.zip | |
Move Unstable Book sections for #[global_allocator] and System to std::alloc docs
Diffstat (limited to 'src/liballoc_system')
| -rw-r--r-- | src/liballoc_system/lib.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index 2b748c4702d..64348e05de7 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -44,6 +44,29 @@ use core::alloc::{Alloc, GlobalAlloc, AllocErr, Layout}; use core::ptr::NonNull; /// The default memory allocator provided by the operating system. +/// +/// This is based on `malloc` on Unix platforms and `HeapAlloc` on Windows, +/// plus related functions. +/// +/// This type can be used in a `static` item +/// with the `#[global_allocator]` attribute +/// to force the global allocator to be the system’s one. +/// (The default is jemalloc for executables, on some platforms.) +/// +/// ```rust +/// use std::alloc::System; +/// +/// #[global_allocator] +/// static A: System = System; +/// +/// fn main() { +/// let a = Box::new(4); // Allocates from the system allocator. +/// println!("{}", a); +/// } +/// ``` +/// +/// It can also be used directly to allocate memory +/// independently of the standard library’s global allocator. #[stable(feature = "alloc_system_type", since = "1.28.0")] pub struct System; |
