3 ms·
Garbage collected languages (Java, JS) have significant overhead, and unpredictable latency spikes. Scope-based memory management (C++) has copying overhead an
by freeone3000 6y ago
Garbage collected languages (Java, JS) have significant overhead, and unpredictable latency spikes.
Scope-based memory management (C++) has copying overhead and destruction overhead, and a whole lot of complexity to avoid those.
Ownership-based memory management removes most of the overhead associated with copying and destruction in a less-complex fashion.
- ben-schaaf 6y agoNote C++'s semantics are akin to ownership, it just has different defaults and none of the safety guarantees. A std::vector is owned by the current scope, ownership can be passed around using std::move and references can be taken using &.
- rwmj 6y agoBad garbage collector implementations, but not GC in general. malloc/free can have latency spikes too. Also not every programming problem in the world is a memory-constrained hard real time problem - in fact, I would say almost all of them are not. Memory ownership is certainly an interesting thing to have in your arsenal, but a whole class of problems (especially anything with a graph or modestly complex interlinked data structure) can't easily be reasoned about using this model, or you end up copying stuff anyway to get around the borrow checker. Having said all that, I'd really like to see a language that lets you use a garbage collector 99% of the time for ease of use, but allows you to use other models for the small sections of the code which need it or within certain designated real time threads.
- mhh__ 6y agoD let's you do that if you want.
- megameter 6y agoI beg to differ. For a sufficiently large time scale, every programming problem is a memory-constrained hard real time problem.
- vips7L 6y agoYou're looking for D! https://dlang.org/spec/function.html#nogc-functions https://dlang.org/spec/function.html#nogc-functions
- mhh__ 6y agoOwnership is a conservative restriction of allowed behaviours (i.e. rust still has ref counts), the three approaches don't do exactly the same job