mirror of
https://github.com/bspeice/speice.io
synced 2024-11-05 01:28:09 -05:00
Minor updates
This commit is contained in:
parent
555eca2660
commit
ab09489d32
@ -16,11 +16,11 @@ type all the time, but there's a rich history of the Rust language itself wrappe
|
|||||||
|
|
||||||
In a similar vein, I want you to look at code and understand memory;
|
In a similar vein, I want you to look at code and understand memory;
|
||||||
the complex choreography of processor, operating system, and program that frees you
|
the complex choreography of processor, operating system, and program that frees you
|
||||||
to focus on functionality far beyond frivolous book-keeping. The Rust compiler relieves
|
to focus on functionality far-flung from frivolous book-keeping. The Rust compiler relieves
|
||||||
a great deal of the cognitive burden associated with memory management, but let's make time
|
a great deal of the cognitive burden associated with memory management, but let's make time
|
||||||
to explore what's going on under the hood.
|
to explore what's going on under the hood.
|
||||||
|
|
||||||
Let's learn a bit about allocating memory in Rust.
|
Let's learn a bit about memory in Rust.
|
||||||
|
|
||||||
# Table of Contents
|
# Table of Contents
|
||||||
|
|
||||||
@ -30,11 +30,11 @@ section for easy citation in the future. To that end, a table of contents is pro
|
|||||||
to assist in easy navigation:
|
to assist in easy navigation:
|
||||||
|
|
||||||
- [Foreword](#foreword)
|
- [Foreword](#foreword)
|
||||||
- Non-Heap Memory Types
|
- [Non-Heap Memory Types](#non-heap-memory-types)
|
||||||
- Piling On - the Heap in Rust
|
- [Piling On - Rust and the Heap](#piling-on-rust-and-the-heap)
|
||||||
- Compiler Optimizations Make Everything Complicated
|
- [Compiler Optimizations Make Everything Complicated](#compiler-optimizations-make-everything-complicated)
|
||||||
- Summary: When Does Rust Allocate?
|
- Summary: When Does Rust Allocate?
|
||||||
- Appendix and Further Reading
|
- [Appendix and Further Reading](#appendix-and-further-reading)
|
||||||
|
|
||||||
# Foreword
|
# Foreword
|
||||||
|
|
||||||
@ -75,9 +75,7 @@ include a warning worth repeating here:
|
|||||||
> Rust does not currently have a rigorously and formally defined memory model.
|
> Rust does not currently have a rigorously and formally defined memory model.
|
||||||
> - the [Rust docs](https://doc.rust-lang.org/std/ptr/fn.read_volatile.html)
|
> - the [Rust docs](https://doc.rust-lang.org/std/ptr/fn.read_volatile.html)
|
||||||
|
|
||||||
# Distinguishing regions of memory
|
# Non-Heap Memory Types
|
||||||
|
|
||||||
# Rust and the Stack
|
|
||||||
|
|
||||||
Example: Why doesn't `Vec::new()` go to the allocator?
|
Example: Why doesn't `Vec::new()` go to the allocator?
|
||||||
|
|
||||||
@ -91,7 +89,7 @@ Questions:
|
|||||||
6. How are arrays allocated?
|
6. How are arrays allocated?
|
||||||
7. Legal to pass an array as an argument?
|
7. Legal to pass an array as an argument?
|
||||||
|
|
||||||
# Rust and the Heap
|
# Piling On - Rust and the Heap
|
||||||
|
|
||||||
Example: How to trigger a heap allocation
|
Example: How to trigger a heap allocation
|
||||||
|
|
||||||
@ -99,13 +97,20 @@ Questions:
|
|||||||
|
|
||||||
1. Where do collection types allocate memory?
|
1. Where do collection types allocate memory?
|
||||||
2. Does a Box<> always allocate heap?
|
2. Does a Box<> always allocate heap?
|
||||||
|
- Yes, with exception of compiler optimizations
|
||||||
3. Passing Box<Trait> vs. genericizing/monomorphization
|
3. Passing Box<Trait> vs. genericizing/monomorphization
|
||||||
|
- If it uses `dyn Trait`, it's on the heap.
|
||||||
4. Other pointer types? Do Rc<>/Arc<> force heap allocation?
|
4. Other pointer types? Do Rc<>/Arc<> force heap allocation?
|
||||||
|
- Maybe? Part of the alloc crate, but should use qadapt to check
|
||||||
|
|
||||||
# Understanding compiler optimizations
|
# Compiler Optimizations Make Everything Complicated
|
||||||
|
|
||||||
Example: Compiler stripping out allocations of Box<>, Vec::push()
|
Example: Compiler stripping out allocations of Box<>, Vec::push()
|
||||||
|
|
||||||
|
# Appendix and Further Reading
|
||||||
|
|
||||||
|
[Embedonomicon]:
|
||||||
|
|
||||||
[embedonomicon]: https://docs.rust-embedded.org/embedonomicon/
|
[embedonomicon]: https://docs.rust-embedded.org/embedonomicon/
|
||||||
[libc]: CRATES.IO LINK
|
[libc]: CRATES.IO LINK
|
||||||
[winapi]: CRATES.IO LINK
|
[winapi]: CRATES.IO LINK
|
||||||
|
Loading…
Reference in New Issue
Block a user