advance/smart-pointer/rc-arc #1064
Replies: 20 comments 24 replies
-
这一章写的这么精彩,竟然没有评论吗 |
Beta Was this translation helpful? Give feedback.
-
读文章感觉困难的同学不要灰心,可以在写过一段时间代码后再来看,会有一种豁然开朗的感觉!我就是这样的。 |
Beta Was this translation helpful? Give feedback.
-
以上代码我们使用 Rc::new 创建了一个新的 Rc 智能指针并赋给变量 a,该指针指向底层的字符串数据。这里在我的理解中,String是一个智能指针,在栈上,新的Rc智能指针指向该栈上String吧 |
Beta Was this translation helpful? Give feedback.
-
都讲了智能指针了,也没有看到内存动态分配,rust 中是不需要这个功能吗? |
Beta Was this translation helpful? Give feedback.
-
大家,请记得坚持捏!如果坚持不下去,先至少把rustlings对照着写完吧! |
Beta Was this translation helpful? Give feedback.
-
有没有rust 相关的project 来练练手 |
Beta Was this translation helpful? Give feedback.
-
怎么可能不常见呢?多线程编程下,多个线程功操作同一个变量。 |
Beta Was this translation helpful? Give feedback.
-
最后这个例子忘join了吧 |
Beta Was this translation helpful? Give feedback.
-
这样一个场景 struct Foo { 其中 set的keyt自来于map的key, 但并不是map的所有key都在set中 那么复制一份String 和 创建一个Rc 实践上哪个更好 |
Beta Was this translation helpful? Give feedback.
-
感觉是不是可以把Rc和Arc 的内部结构也讲讲,比如他的内存结构啥的,这样看完感觉其实Rc里的那个计数器到底是如何计数的还是不太明白 |
Beta Was this translation helpful? Give feedback.
-
"...允许一个数据资源在同一时刻拥有多个所有者...",我认为开头的表述是不严谨的。 |
Beta Was this translation helpful? Give feedback.
-
rc解决的是引用生命周期的复杂性,可以这么理解么? |
Beta Was this translation helpful? Give feedback.
-
不能说毫不相干,只能说和objc一毛一样? |
Beta Was this translation helpful? Give feedback.
-
好奇一个问题,既然Rc用的是引用计数,它是怎么解决循环引用的问题 |
Beta Was this translation helpful? Give feedback.
-
文章开头说到
这里抛出一个问题,直接使用引用&类型不也可以实现吗? let s = String::from("hello, world");
// s在这里被转移给a
let a = Box::new(&s);
// 报错!此处继续尝试将 s 转移给 b
let b = Box::new(&s);
println!("{}",a);
println!("{}",b); |
Beta Was this translation helpful? Give feedback.
-
fn operate_arc(){
|
Beta Was this translation helpful? Give feedback.
-
第一个例子也可以这样 fn main() {
let s = String::from("hello, world");
// s在这里被转移给a
let a = Box::new(s);
// 把a解引用
let _b = Box::new(*a);
} |
Beta Was this translation helpful? Give feedback.
-
这两句代码中, 我不明白为什么 Rc::clone(&a);和Rc::strong_count(&a) 要使用&a而不是单纯的a呢? |
Beta Was this translation helpful? Give feedback.
-
advance/smart-pointer/rc-arc
https://course.rs/advance/smart-pointer/rc-arc.html
Beta Was this translation helpful? Give feedback.
All reactions