Skip to content

Commit 62b3ff2

Browse files
authored
Merge pull request #1206 from Rosto75/master
A couple of fixes for the `Box, stack and heap` chapter.
2 parents 0a22b4f + 7f797da commit 62b3ff2

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/std/box.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Box, stack and heap
22

33
All values in Rust are stack allocated by default. Values can be *boxed*
4-
(allocated in the heap) by creating a `Box<T>`. A box is a smart pointer to a
4+
(allocated on the heap) by creating a `Box<T>`. A box is a smart pointer to a
55
heap allocated value of type `T`. When a box goes out of scope, its destructor
6-
is called, the inner object is destroyed, and the memory in the heap is freed.
6+
is called, the inner object is destroyed, and the memory on the heap is freed.
77

88
Boxed values can be dereferenced using the `*` operator; this removes one layer
99
of indirection.
@@ -29,7 +29,7 @@ fn origin() -> Point {
2929
}
3030
3131
fn boxed_origin() -> Box<Point> {
32-
// Allocate this point in the heap, and return a pointer to it
32+
// Allocate this point on the heap, and return a pointer to it
3333
Box::new(Point { x: 0.0, y: 0.0 })
3434
}
3535
@@ -54,22 +54,22 @@ fn main() {
5454
// Double indirection
5555
let box_in_a_box: Box<Box<Point>> = Box::new(boxed_origin());
5656
57-
println!("Point occupies {} bytes in the stack",
57+
println!("Point occupies {} bytes on the stack",
5858
mem::size_of_val(&point));
59-
println!("Rectangle occupies {} bytes in the stack",
59+
println!("Rectangle occupies {} bytes on the stack",
6060
mem::size_of_val(&rectangle));
6161
62-
// box size = pointer size
63-
println!("Boxed point occupies {} bytes in the stack",
62+
// box size == pointer size
63+
println!("Boxed point occupies {} bytes on the stack",
6464
mem::size_of_val(&boxed_point));
65-
println!("Boxed rectangle occupies {} bytes in the stack",
65+
println!("Boxed rectangle occupies {} bytes on the stack",
6666
mem::size_of_val(&boxed_rectangle));
67-
println!("Boxed box occupies {} bytes in the stack",
67+
println!("Boxed box occupies {} bytes on the stack",
6868
mem::size_of_val(&box_in_a_box));
6969
7070
// Copy the data contained in `boxed_point` into `unboxed_point`
7171
let unboxed_point: Point = *boxed_point;
72-
println!("Unboxed point occupies {} bytes in the stack",
72+
println!("Unboxed point occupies {} bytes on the stack",
7373
mem::size_of_val(&unboxed_point));
7474
}
7575
```

0 commit comments

Comments
 (0)