mirror of
https://github.com/google/comprehensive-rust.git
synced 2025-01-19 20:59:36 +02:00
Add to speaker notes rc.md (#366)
* Update rc.md * Fix wording and formatting * Update rc.md --------- Co-authored-by: Andrew Walbran <qwandor@google.com>
This commit is contained in:
parent
973e27a322
commit
e73b163d77
@ -28,9 +28,12 @@ fn main() {
|
||||
|
||||
<details>
|
||||
|
||||
* `Rc`'s Count ensures that its contained value is valid for as long as there are references.
|
||||
* Like C++'s `std::shared_ptr`.
|
||||
* `clone` is cheap: creates a pointer to the same allocation and increases the reference count.
|
||||
* `clone` is cheap: it creates a pointer to the same allocation and increases the reference count. Does not make a deep clone and can generally be ignored when looking for performance issues in code.
|
||||
* `make_mut` actually clones the inner value if necessary ("clone-on-write") and returns a mutable reference.
|
||||
* Use `Rc::strong_count` to check the reference count.
|
||||
* Compare the different datatypes mentioned. `Box` enables (im)mutable borrows that are enforced at compile time. `RefCell` enables (im)mutable borrows that are enforced at run time and will panic if it fails at runtime.
|
||||
* You can `downgrade()` a `Rc` into a *weakly reference-counted* object to
|
||||
create cycles that will be dropped properly (likely in combination with
|
||||
`RefCell`).
|
||||
|
Loading…
x
Reference in New Issue
Block a user