From 2c743c5896815aee2faa885e5298d82c67727139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Tue, 18 Jun 2019 14:05:53 +0200 Subject: [PATCH 1/2] Reword stack/heap memory allocation description. Changed all the instances of `in the heap/stack` into `on the heap/stack`. This form is widely accepted within the industry, and consistent with the "The Rust Programming Language" book. --- src/std/box.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/std/box.md b/src/std/box.md index 64856d7aa7..ede2b81429 100644 --- a/src/std/box.md +++ b/src/std/box.md @@ -1,9 +1,9 @@ # Box, stack and heap All values in Rust are stack allocated by default. Values can be *boxed* -(allocated in the heap) by creating a `Box`. A box is a smart pointer to a +(allocated on the heap) by creating a `Box`. A box is a smart pointer to a heap allocated value of type `T`. When a box goes out of scope, its destructor -is called, the inner object is destroyed, and the memory in the heap is freed. +is called, the inner object is destroyed, and the memory on the heap is freed. Boxed values can be dereferenced using the `*` operator; this removes one layer of indirection. @@ -29,7 +29,7 @@ fn origin() -> Point { } fn boxed_origin() -> Box { - // Allocate this point in the heap, and return a pointer to it + // Allocate this point on the heap, and return a pointer to it Box::new(Point { x: 0.0, y: 0.0 }) } @@ -54,22 +54,22 @@ fn main() { // Double indirection let box_in_a_box: Box> = Box::new(boxed_origin()); - println!("Point occupies {} bytes in the stack", + println!("Point occupies {} bytes on the stack", mem::size_of_val(&point)); - println!("Rectangle occupies {} bytes in the stack", + println!("Rectangle occupies {} bytes on the stack", mem::size_of_val(&rectangle)); // box size = pointer size - println!("Boxed point occupies {} bytes in the stack", + println!("Boxed point occupies {} bytes on the stack", mem::size_of_val(&boxed_point)); - println!("Boxed rectangle occupies {} bytes in the stack", + println!("Boxed rectangle occupies {} bytes on the stack", mem::size_of_val(&boxed_rectangle)); - println!("Boxed box occupies {} bytes in the stack", + println!("Boxed box occupies {} bytes on the stack", mem::size_of_val(&box_in_a_box)); // Copy the data contained in `boxed_point` into `unboxed_point` let unboxed_point: Point = *boxed_point; - println!("Unboxed point occupies {} bytes in the stack", + println!("Unboxed point occupies {} bytes on the stack", mem::size_of_val(&unboxed_point)); } ``` \ No newline at end of file From 7f797da7c9da536196ab3f0ae8aa5b1a45010674 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20R=C3=B3=C5=BCa=C5=84ski?= Date: Tue, 18 Jun 2019 14:15:37 +0200 Subject: [PATCH 2/2] Fix inconsistent use of `=` sign in the comment. Changed a single `=` (assignment) into `==` (equality), which was clearly the author's original intention. --- src/std/box.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/box.md b/src/std/box.md index ede2b81429..8d45e1a44e 100644 --- a/src/std/box.md +++ b/src/std/box.md @@ -59,7 +59,7 @@ fn main() { println!("Rectangle occupies {} bytes on the stack", mem::size_of_val(&rectangle)); - // box size = pointer size + // box size == pointer size println!("Boxed point occupies {} bytes on the stack", mem::size_of_val(&boxed_point)); println!("Boxed rectangle occupies {} bytes on the stack",