about summary refs log tree commit diff
path: root/src/liballoc_system
diff options
context:
space:
mode:
authorSimon Sapin <simon.sapin@exyr.org>2018-05-31 20:22:59 +0200
committerSimon Sapin <simon.sapin@exyr.org>2018-06-11 13:48:57 -0700
commita24924f6834ea6e5bd813d006a12aef8e5dbd5e9 (patch)
tree8af929586f9bc74184b8682ebaa486c2a97a8dfa /src/liballoc_system
parentfd6e08a1e6bbccd00e70b23ac72dd9a9a633be30 (diff)
downloadrust-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.rs23
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;