知识卡片
Rc 共享同一份所有权
Rc<T> 提供单线程共享所有权。当多个对象都需要持有堆上同一节点且很难预先确定谁最后使用,可分别持有 Rc 句柄。Rc::clone(&a) 复制句柄,不深复制 T。共享时一般只能通过它获得 &T。
相关卡片 [[Box 提供独占堆存储]]
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- 智能指针 Rc<T>, the Reference Counted Smart Pointer · 查看原书依据
Instead, we’ll change our definition of List to use Rc<T> in place of Box<T>, as shown in Listing 15-18. Each Cons variant will now hold a value and an Rc<T> pointing to a List.
参考来源
- 位置:《The Rust Programming Language(第2版)》第15章 智能指针(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c15.xhtml`,块 0200)
- 结论依据:原文以两个新表共享第三个列表对照独占 Box。
- 原始内容:Instead, we’ll change our definition of List to use Rc<T> in place of Box<T>, as shown in Listing 15-18. Each Cons variant will now hold a value and an Rc<T> pointing to a List.