4 ms·
Reference counting in C++ can be done really well even in the absence of language support. For example, with the Qt library you can pass objects around by valu
by jkarneges 11y ago
Reference counting in C++ can be done really well even in the absence of language support.
For example, with the Qt library you can pass objects around by value, yet behind the scenes everything is reference counted with automatic copy-on-write. It's the best of all worlds. You get easy, value-based coding (no pointers), speed (because deep down everything is a reference), and deterministic destruction (no GC). http://doc.qt.io/qt-5/implicit-sharing.html http://doc.qt.io/qt-5/implicit-sharing.html
I'm curious if any languages have adopted a Qt-style approach natively.
- beagle3 11y agoI know for sure the K (of the J / K / APL) family does, and I suspect they all do.
- ridiculous_fish 11y agoYes, Swift works this way. Arrays, dictionaries, and sets are value types and cannot be implicitly shared, which eliminates a large class of bugs. It's kind of amazing, isn't it!
- aruggirello 11y ago> For example, with the Qt library you can pass objects around by value, yet behind the scenes everything is reference counted with automatic copy-on-write. PHP does exactly this, but for arrays and strings only (objects are implicitly passed by reference). So you can pass arrays by value with no performance penalty, as they are actually passed by reference. A COW mechanism ensures you end up with a local copy only if you write to an argument; such mechanism is disabled when passing arguments byref.