New top story on Hacker News: Why Rust easily optimizes out smart pointers where C++ cannot? - The Book

Breaking

Home Top Ad

Responsive Ads Here

Post Top Ad

Responsive Ads Here

Saturday, June 4, 2022

New top story on Hacker News: Why Rust easily optimizes out smart pointers where C++ cannot?

Why Rust easily optimizes out smart pointers where C++ cannot?
7 by codedokode | 6 comments on Hacker News.
I think that this example can be both entertaining and educating. 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. Here is a simple function that adds two numbers using smart pointers. Rust compiles it into two instructions [1], while C++ creates about 100 instructions [2] including unnecessary memory locks. I wonder, is there a way to improve C++ code so that the smart pointers get optimized out? Did I make some mistake that prevents optimization? [1] https://ift.tt/fuvRV7o [2] https://ift.tt/EXUDL26

No comments:

Post a Comment

Post Bottom Ad

Responsive Ads Here

Pages