1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-12-14 22:15:54 +02:00

'Stack Memory' slide isn't really showing stack memory (#996)

This commit is contained in:
Dominik Maier 2023-07-18 07:35:20 +02:00 committed by GitHub
parent cb689be312
commit aabe0c0a96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,7 +1,7 @@
# Stack Memory
# Stack and Heap Example
Creating a `String` puts fixed-sized data on the stack and dynamically sized
data on the heap:
Creating a `String` puts fixed-sized metadata on the stack and dynamically sized
data, the actual string, on the heap:
```rust,editable
fn main() {
@ -40,7 +40,7 @@ fn main() {
// String provides no guarantees about its layout, so this could lead to
// undefined behavior.
unsafe {
let (capacity, ptr, len): (usize, usize, usize) = std::mem::transmute(s1);
let (ptr, capacity, len): (usize, usize, usize) = std::mem::transmute(s1);
println!("ptr = {ptr:#x}, len = {len}, capacity = {capacity}");
}
}