10. Smart Pointers - From Python to Rust

preview_player
Показать описание
Demonstration of smart pointers in Python and Rust

Рекомендации по теме
Комментарии
Автор

8:10 I think what you are saying here is not entirely correct. Line 27 and 25 call both the exact same method. In line 25 explicitly and in line 27 using the method operator, but in both cases the same method is invoked which does *not* make a deep copy, in any case. That would also destroy the purpose of Rc.
The Rust book says the following on this topic: "We could have called a.clone() rather than Rc::clone(&a), but Rust’s convention is to use Rc::clone in this case. The implementation of Rc::clone doesn’t make a deep copy of all the data like most types’ implementations of clone do. The call to Rc::clone only increments the reference count, which doesn’t take much time. Deep copies of data can take a lot of time. By using Rc::clone for reference counting, we can visually distinguish between the deep-copy kinds of clones and the kinds of clones that increase the reference count. When looking for performance problems in the code, we only need to consider the deep-copy clones and can disregard calls to Rc::clone."

embeddedbastler
Автор

@17:13 and line number 15 & 16, querying for rc strong count why it is coming up as 2 for both.
I feel 2 is ok when we are querying stong count for rc_a, bcz rc_a s refering to rc_examples and rc_b is also refering to rc_a inturrn pointing to rc_examples
but y count is 2 for rc_b it should b 1 right, bcz rc_b is just refering only to rc_a

Could you pls clarify.
As per my understanding, rc will help to have multiple read only owners to a memory location, so here rc_a and rc_b are 2 read only owners to the rc_examples.

bjugdbjk
join shbcf.ru