You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/memory-allocation-and-lifetime.md
+2-10Lines changed: 2 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,7 @@ r[alloc]
2
2
# Memory allocation and lifetime
3
3
4
4
r[alloc.static]
5
-
The _items_ of a program are those functions, modules, and types that have their
6
-
value calculated at compile-time and stored uniquely in the memory image of the
7
-
rust process. Items are neither dynamically allocated nor freed.
5
+
The _items_ of a program are those functions, modules, and types that have their value calculated at compile-time and stored uniquely in the memory image of the rust process. Items are neither dynamically allocated nor freed.
8
6
9
7
r[alloc.dynamic]
10
-
The _heap_ is a general term that describes boxes. The lifetime of an
11
-
allocation in the heap depends on the lifetime of the box values pointing to
12
-
it. Since box values may themselves be passed in and out of frames, or stored
13
-
in the heap, heap allocations may outlive the frame they are allocated within.
14
-
An allocation in the heap is guaranteed to reside at a single location in the
15
-
heap for the whole lifetime of the allocation - it will never be relocated as
16
-
a result of moving a box value.
8
+
The _heap_ is a general term that describes boxes. The lifetime of an allocation in the heap depends on the lifetime of the box values pointing to it. Since box values may themselves be passed in and out of frames, or stored in the heap, heap allocations may outlive the frame they are allocated within. An allocation in the heap is guaranteed to reside at a single location in the heap for the whole lifetime of the allocation - it will never be relocated as a result of moving a box value.
Copy file name to clipboardExpand all lines: src/variables.md
+7-19Lines changed: 7 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,33 +2,21 @@ r[variable]
2
2
# Variables
3
3
4
4
r[variable.intro]
5
-
A _variable_ is a component of a stack frame, either a named function parameter,
6
-
an anonymous [temporary](expressions.md#temporaries), or a named local
7
-
variable.
5
+
A _variable_ is a component of a stack frame, either a named function parameter, an anonymous [temporary](expressions.md#temporaries), or a named local variable.
8
6
9
7
r[variable.local]
10
-
A _local variable_ (or *stack-local* allocation) holds a value directly,
11
-
allocated within the stack's memory. The value is a part of the stack frame.
8
+
A _local variable_ (or *stack-local* allocation) holds a value directly, allocated within the stack's memory. The value is a part of the stack frame.
12
9
13
10
r[variable.local-mut]
14
-
Local variables are immutable unless declared otherwise. For example:
15
-
`let mut x = ...`.
11
+
Local variables are immutable unless declared otherwise. For example: `let mut x = ...`.
16
12
17
13
r[variable.param-mut]
18
-
Function parameters are immutable unless declared with `mut`. The `mut` keyword
19
-
applies only to the following parameter. For example: `|mut x, y|` and
20
-
`fn f(mut x: Box<i32>, y: Box<i32>)` declare one mutable variable `x` and one
21
-
immutable variable `y`.
14
+
Function parameters are immutable unless declared with `mut`. The `mut` keyword applies only to the following parameter. For example: `|mut x, y|` and `fn f(mut x: Box<i32>, y: Box<i32>)` declare one mutable variable `x` and one immutable variable `y`.
22
15
23
16
r[variable.init]
24
-
Local variables are not initialized when allocated. Instead, the entire frame
25
-
worth of local variables are allocated, on frame-entry, in an uninitialized
26
-
state. Subsequent statements within a function may or may not initialize the
27
-
local variables. Local variables can be used only after they have been
28
-
initialized through all reachable control flow paths.
29
-
30
-
In this next example, `init_after_if` is initialized after the [`if` expression]
31
-
while `uninit_after_if` is not because it is not initialized in the `else` case.
17
+
Local variables are not initialized when allocated. Instead, the entire frame worth of local variables are allocated, on frame-entry, in an uninitialized state. Subsequent statements within a function may or may not initialize the local variables. Local variables can be used only after they have been initialized through all reachable control flow paths.
18
+
19
+
In this next example, `init_after_if` is initialized after the [`if` expression] while `uninit_after_if` is not because it is not initialized in the `else` case.
0 commit comments