Skip to content

Commit e07d838

Browse files
committed
---
yaml --- r: 39772 b: refs/heads/incoming c: 22ed202 h: refs/heads/master v: v3
1 parent bee3594 commit e07d838

File tree

2 files changed

+1
-71
lines changed

2 files changed

+1
-71
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 3d5418789064fdb463e872a4e651af1c628a3650
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278
9-
refs/heads/incoming: fe0f84823aeaef324eb3bb2d7131c80b9630f370
9+
refs/heads/incoming: 22ed202b6199bb9108deb78d108294f0d5cf75c5
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/doc/tutorial.md

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -841,76 +841,6 @@ as in this example that unpacks the first value from a tuple and returns it.
841841
fn first((value, _): (int, float)) -> int { value }
842842
~~~
843843

844-
845-
# The Rust memory model
846-
847-
At this junction, let's take a detour to explain the concepts involved
848-
in Rust's memory model. We've seen some of Rust's pointer sigils (`@`,
849-
`~`, and `&`) float by in a few examples, and we aren't going to get
850-
much further without explaining them. Rust has a very particular
851-
approach to memory management that plays a significant role in shaping
852-
the subjective experience of programming in the
853-
language. Understanding the memory landscape will illuminate several
854-
of Rust's unique features as we encounter them.
855-
856-
Rust has three competing goals that inform its view of memory:
857-
858-
* Memory safety: Memory that the Rust language can observe must be
859-
guaranteed to be valid. Under normal circumstances, it must be
860-
impossible for Rust to trigger a segmentation fault or leak memory.
861-
* Performance: High-performance low-level code must be able to use
862-
a number of different allocation strategies. Tracing garbage collection must be
863-
optional and, if it is not desired, memory safety must not be compromised.
864-
Less performance-critical, high-level code should be able to employ a single,
865-
garbage-collection-based, heap allocation strategy.
866-
* Concurrency: Rust code must be free of in-memory data races. (Note that other
867-
types of races are still possible.)
868-
869-
## How performance considerations influence the memory model
870-
871-
Most languages that offer strong memory safety guarantees rely on a
872-
garbage-collected heap to manage all of the objects. This approach is
873-
straightforward both in concept and in implementation, but has
874-
significant costs. Languages that follow this path tend to
875-
aggressively pursue ways to ameliorate allocation costs (think the
876-
Java Virtual Machine). Rust supports this strategy with _managed
877-
boxes_: memory allocated on the heap whose lifetime is managed
878-
by the garbage collector.
879-
880-
By comparison, languages like C++ offer very precise control over
881-
where objects are allocated. In particular, it is common to allocate them
882-
directly on the stack, avoiding expensive heap allocation. In Rust
883-
this is possible as well, and the compiler uses a [clever _pointer
884-
lifetime analysis_][borrow] to ensure that no variable can refer to stack
885-
objects after they are destroyed.
886-
887-
[borrow]: tutorial-borrowed-ptr.html
888-
889-
## How concurrency considerations influence the memory model
890-
891-
Memory safety in a concurrent environment involves avoiding race
892-
conditions between two threads of execution accessing the same
893-
memory. Even high-level languages often require programmers to make
894-
correct use of locking to ensure that a program is free of races.
895-
896-
Rust starts from the position that memory cannot be shared between
897-
tasks. Experience in other languages has proven that isolating each
898-
task's heap from the others is a reliable strategy and one that is
899-
easy for programmers to reason about. Heap isolation has the
900-
additional benefit that garbage collection must only be done
901-
per-heap. Rust never "stops the world" to reclaim memory.
902-
903-
Complete isolation of heaps between tasks would, however, mean that
904-
any data transferred between tasks must be copied. While this is a
905-
fine and useful way to implement communication between tasks, it is
906-
also very inefficient for large data structures. To reduce the amount
907-
of copying, Rust also uses a global _exchange heap_. Objects allocated
908-
in the exchange heap have _ownership semantics_, meaning that there is
909-
only a single variable that refers to them. For this reason, they are
910-
referred to as _owned boxes_. All tasks may allocate objects on the
911-
exchange heap, then transfer ownership of those objects to other
912-
tasks, avoiding expensive copies.
913-
914844
# Boxes and pointers
915845

916846
Many modern languages have a so-called "uniform representation" for

0 commit comments

Comments
 (0)