Skip to content

Commit 649953e

Browse files
committed
Rollup merge of rust-lang#30404 - Shiney:ImprovedStackHeap, r=steveklabnik
…entation clearer I could not use colors as suggested for rust-lang#29854 because Github doesn't support these in markdown, however this solution may be better for color-blind readers.
2 parents 8d87ed0 + 62fa40f commit 649953e

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/doc/book/the-stack-and-the-heap.md

+22-20
Original file line numberDiff line numberDiff line change
@@ -130,63 +130,64 @@ on the stack is the first one you retrieve from it.
130130
Let’s try a three-deep example:
131131

132132
```rust
133-
fn bar() {
133+
fn italic() {
134134
let i = 6;
135135
}
136136

137-
fn foo() {
137+
fn bold() {
138138
let a = 5;
139139
let b = 100;
140140
let c = 1;
141141

142-
bar();
142+
italic();
143143
}
144144

145145
fn main() {
146146
let x = 42;
147147

148-
foo();
148+
bold();
149149
}
150150
```
151151

152+
We have some kooky function names to make the diagrams clearer.
153+
152154
Okay, first, we call `main()`:
153155

154156
| Address | Name | Value |
155157
|---------|------|-------|
156158
| 0 | x | 42 |
157159

158-
Next up, `main()` calls `foo()`:
160+
Next up, `main()` calls `bold()`:
159161

160162
| Address | Name | Value |
161163
|---------|------|-------|
162-
| 3 | c | 1 |
163-
| 2 | b | 100 |
164-
| 1 | a | 5 |
164+
| **3** | **c**|**1** |
165+
| **2** | **b**|**100**|
166+
| **1** | **a**| **5** |
165167
| 0 | x | 42 |
166168

167-
And then `foo()` calls `bar()`:
169+
And then `bold()` calls `italic()`:
168170

169171
| Address | Name | Value |
170172
|---------|------|-------|
171-
| 4 | i | 6 |
172-
| 3 | c | 1 |
173-
| 2 | b | 100 |
174-
| 1 | a | 5 |
173+
| *4* | *i* | *6* |
174+
| **3** | **c**|**1** |
175+
| **2** | **b**|**100**|
176+
| **1** | **a**| **5** |
175177
| 0 | x | 42 |
176-
177178
Whew! Our stack is growing tall.
178179

179-
After `bar()` is over, its frame is deallocated, leaving just `foo()` and
180+
After `italic()` is over, its frame is deallocated, leaving just `bold()` and
180181
`main()`:
181182

182183
| Address | Name | Value |
183184
|---------|------|-------|
184-
| 3 | c | 1 |
185-
| 2 | b | 100 |
186-
| 1 | a | 5 |
187-
| 0 | x | 42 |
185+
| **3** | **c**|**1** |
186+
| **2** | **b**|**100**|
187+
| **1** | **a**| **5** |
188+
| 0 | x | 42 |
188189

189-
And then `foo()` ends, leaving just `main()`:
190+
And then `bold()` ends, leaving just `main()`:
190191

191192
| Address | Name | Value |
192193
|---------|------|-------|
@@ -578,3 +579,4 @@ comes at the cost of either significant runtime support (e.g. in the form of a
578579
garbage collector) or significant programmer effort (in the form of explicit
579580
memory management calls that require verification not provided by the Rust
580581
compiler).
582+

0 commit comments

Comments
 (0)