Arc
Arc<T>
可透過 Arc::clone
取得共享唯讀存取權:
Speaker Notes
Arc
代表「原子參考計數」,這個Rc
的執行緒安全版本會採用原子性 運算。Arc<T>
implementsClone
whether or notT
does. It implementsSend
andSync
if and only ifT
implements them both.Arc::clone()
會導致執行原子性運算的費用,但之後使用得到的T
不需任何費用。- 留意參考循環,
Arc
並不使用垃圾收集器進行偵測。std::sync::Weak
可協助執行這項功能。