Skip to content

Commit 818d224

Browse files
committed
Fix out of date unstable book entries for alloc_* features.
1 parent cbf5d39 commit 818d224

File tree

3 files changed

+26
-60
lines changed

3 files changed

+26
-60
lines changed

src/doc/unstable-book/src/library-features/alloc-jemalloc.md

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,6 @@ See also [`alloc_system`](library-features/alloc-system.html).
88

99
------------------------
1010

11-
The compiler currently ships two default allocators: `alloc_system` and
12-
`alloc_jemalloc` (some targets don't have jemalloc, however). These allocators
13-
are normal Rust crates and contain an implementation of the routines to
14-
allocate and deallocate memory. The standard library is not compiled assuming
15-
either one, and the compiler will decide which allocator is in use at
16-
compile-time depending on the type of output artifact being produced.
17-
18-
Binaries generated by the compiler will use `alloc_jemalloc` by default (where
19-
available). In this situation the compiler "controls the world" in the sense of
20-
it has power over the final link. Primarily this means that the allocator
21-
decision can be left up the compiler.
22-
23-
Dynamic and static libraries, however, will use `alloc_system` by default. Here
24-
Rust is typically a 'guest' in another application or another world where it
25-
cannot authoritatively decide what allocator is in use. As a result it resorts
26-
back to the standard APIs (e.g. `malloc` and `free`) for acquiring and releasing
27-
memory.
28-
29-
# Switching Allocators
30-
31-
Although the compiler's default choices may work most of the time, it's often
32-
necessary to tweak certain aspects. Overriding the compiler's decision about
33-
which allocator is in use is done simply by linking to the desired allocator:
34-
35-
```rust,no_run
36-
#![feature(alloc_system)]
37-
38-
extern crate alloc_system;
39-
40-
fn main() {
41-
let a = Box::new(4); // Allocates from the system allocator.
42-
println!("{}", a);
43-
}
44-
```
45-
46-
In this example the binary generated will not link to jemalloc by default but
47-
instead use the system allocator. Conversely to generate a dynamic library which
48-
uses jemalloc by default one would write:
49-
50-
```rust,ignore
51-
#![feature(alloc_jemalloc)]
52-
#![crate_type = "dylib"]
53-
54-
extern crate alloc_jemalloc;
55-
56-
pub fn foo() {
57-
let a = Box::new(4); // Allocates from jemalloc.
58-
println!("{}", a);
59-
}
60-
# fn main() {}
61-
```
11+
This feature has been replaced by [the `jemallocator` crate on crates.io.][jemallocator].
6212

13+
[jemallocator]: https://crates.io/crates/jemallocator

src/doc/unstable-book/src/library-features/alloc-system.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# `alloc_system`
22

3-
The tracking issue for this feature is: [#33082]
3+
The tracking issue for this feature is: [#32838]
44

5-
[#33082]: https://github.com/rust-lang/rust/issues/33082
5+
[#32838]: https://github.com/rust-lang/rust/issues/32838
66

7-
See also [`alloc_jemalloc`](library-features/alloc-jemalloc.html).
7+
See also [`global_allocator`](language-features/global-allocator.html).
88

99
------------------------
1010

@@ -30,13 +30,18 @@ memory.
3030

3131
Although the compiler's default choices may work most of the time, it's often
3232
necessary to tweak certain aspects. Overriding the compiler's decision about
33-
which allocator is in use is done simply by linking to the desired allocator:
33+
which allocator is in use is done through the `#[global_allocator]` attribute:
3434

3535
```rust,no_run
36-
#![feature(alloc_system)]
36+
#![feature(alloc_system, global_allocator, allocator_api)]
3737
3838
extern crate alloc_system;
3939
40+
use alloc_system::System;
41+
42+
#[global_allocator]
43+
static A: System = System;
44+
4045
fn main() {
4146
let a = Box::new(4); // Allocates from the system allocator.
4247
println!("{}", a);
@@ -47,16 +52,26 @@ In this example the binary generated will not link to jemalloc by default but
4752
instead use the system allocator. Conversely to generate a dynamic library which
4853
uses jemalloc by default one would write:
4954

55+
(The `alloc_jemalloc` crate cannot be used to control the global allocator,
56+
crate.io’s `jemallocator` crate provides equivalent functionality.)
57+
58+
```toml
59+
# Cargo.toml
60+
[dependencies]
61+
jemallocator = "0.1"
62+
```
5063
```rust,ignore
51-
#![feature(alloc_jemalloc)]
64+
#![feature(global_allocator)]
5265
#![crate_type = "dylib"]
5366
54-
extern crate alloc_jemalloc;
67+
extern crate jemallocator;
68+
69+
#[global_allocator]
70+
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
5571
5672
pub fn foo() {
5773
let a = Box::new(4); // Allocates from jemalloc.
5874
println!("{}", a);
5975
}
6076
# fn main() {}
6177
```
62-

src/liballoc_system/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#![unstable(feature = "alloc_system",
1515
reason = "this library is unlikely to be stabilized in its current \
1616
form or name",
17-
issue = "27783")]
17+
issue = "32838")]
1818
#![feature(global_allocator)]
1919
#![feature(allocator_api)]
2020
#![feature(alloc)]

0 commit comments

Comments
 (0)