Skip to content

Commit 9c03d51

Browse files
authored
Add a picture to Rc (#2583)
I suppose my `svgbob` skills leave a bit to be desired, but I think the meaning is clear: ![image](https://github.com/user-attachments/assets/09fa2ebd-7364-4d23-bc97-6e7e81a9c82e) Now that I look through the `Rc` implementation, there's a weak count for every strong count, so the `weak: 0` here is inaccurate. But, maybe this is too much of an implementation detail? Should I just concentrate on strong refs? I suppose I could put a `...` in that upper-right box, to suggest there's more going on here?
1 parent 4ce87c5 commit 9c03d51

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/smart-pointers/rc.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ fn main() {
1919
}
2020
```
2121

22+
Each `Rc` points to the same shared data structure, containing strong and weak
23+
pointers and the value:
24+
25+
```bob
26+
Stack Heap
27+
.- - - - - - - -. .- - - - - - - - - - - - - - - - -.
28+
: : : :
29+
: +-----+ : : +-----------+-------------+ :
30+
: a: | o---|---:--+--:-->| count: 2 | value: 10 | :
31+
: +-----+ : | : +-----------+-------------+ :
32+
: b: | o---|---:--+ : :
33+
: +-----+ : `- - - - - - - - - - - - - - - - -'
34+
: :
35+
`- - - - - - - -'
36+
```
37+
2238
- See [`Arc`][2] and [`Mutex`][3] if you are in a multi-threaded context.
2339
- You can _downgrade_ a shared pointer into a [`Weak`][4] pointer to create
2440
cycles that will get dropped.

0 commit comments

Comments
 (0)