File tree 2 files changed +13
-0
lines changed
2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,9 @@ extern "Rust" {
34
34
/// This type implements the [`Alloc`] trait by forwarding calls
35
35
/// to the allocator registered with the `#[global_allocator]` attribute
36
36
/// if there is one, or the `std` crate’s default.
37
+ ///
38
+ /// Note: while this type is unstable, the functionality it provides can be
39
+ /// accessed through the [free functions in `alloc`](index.html#functions).
37
40
#[ unstable( feature = "allocator_api" , issue = "32838" ) ]
38
41
#[ derive( Copy , Clone , Default , Debug ) ]
39
42
pub struct Global ;
Original file line number Diff line number Diff line change 4
4
//! heap allocation in Rust. Boxes provide ownership for this allocation, and
5
5
//! drop their contents when they go out of scope.
6
6
//!
7
+ //! For non-zero-sized values, a [`Box`] will use the [`Global`] allocator for
8
+ //! its allocation. It is valid to convert both ways between a [`Box`] and a
9
+ //! raw pointer allocated with the [`Global`] allocator, given that the
10
+ //! [`Layout`] used with the allocator is correct for the type. More precisely,
11
+ //! a `value: *mut T` that has been allocated with the [`Global`] allocator
12
+ //! with `Layout::for_value(&*value)` may be converted into a box using
13
+ //! `Box::<T>::from_raw(value)`. Conversely, the memory backing a `value: *mut
14
+ //! T` obtained from `Box::<T>::into_raw` may be deallocated using the
15
+ //! [`Global`] allocator with `Layout::for_value(&*value)`.
16
+ //!
7
17
//! # Examples
8
18
//!
9
19
//! Move a value from the stack to the heap by creating a [`Box`]:
You can’t perform that action at this time.
0 commit comments