3 ms·
C++'s std::shared_ptr<T> is not at all like Rust's Rc<T>. std::shared_ptr<T> is more like Arc<T> or Arc<Box<T>> depending on the deleter. Also, your Rust examp
by strager 4y ago
C++'s std::shared_ptr<T> is not at all like Rust's Rc<T>. std::shared_ptr<T> is more like Arc<T> or Arc<Box<T>> depending on the deleter.
Also, your Rust example uses -O (which is -C opt-level=2), but your C++ example uses Clang's -O3 (which is like rustc's -C opt-level=3).
Here are examples which are more similar:
Rust: https://godbolt.org/z/We7ah1ehe https://godbolt.org/z/We7ah1ehe
C++: https://godbolt.org/z/r31jrcbjc https://godbolt.org/z/r31jrcbjc
> Smart pointers are often used in high-performance code (like browser engines) so it is interesting to learn how their usage impacts the generated code.
Browsers like Firefox and Chrome don't use std::shared_ptr. You should research how the compiler optimizes those implementations.