知识卡片
共享拥有可简化复杂借用网
多处要看到同一可变数据时,共享拥有常比复制多份后同步、或维护复杂借用寿命更清楚。单线程可考虑Rc>,跨线程可考虑Arc>,并承担相应动态检查与同步成本。应按模型选择,而不是把智能指针当成失败标志或默认套用。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 3. Concepts References and Smart Pointers · 查看原书依据
shared-owner model. The Rc (for single-threaded code) and Arc (for multithreaded code) smart pointers provide reference counting that supports this shared-ownership model. Continuing with the assumption that mutability is needed, they are typically paired with an inner type that allows interior mutability, independently of Rust’s borrow checking rules: RefCe
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第3章《References and Smart Pointers》(spine7;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch03.html;u112-ch03-052)。
- 结论依据:原文在“shared-owner model”附近的定义、例子或代码支撑本卡核心说明:多处要看到同一可变数据时,共享拥有常比复制多份后同步、或维护复杂借用寿命更清楚。边界按已读前提解释;示例未执行。
- 原始内容:shared-owner model. The Rc (for single-threaded code) and Arc (for multithreaded code) smart pointers provide reference counting that supports this shared-ownership model. Continuing with the assumption that mutability is needed, they are typically paired with an inner type that allows interior mutability, independently of Rust’s borrow checking rules: RefCe