3 ms·
Because GC wastes cycles on the user's machines instead of just hiring a competent developer who can manage memory properly. As we move to a more mobile world,
by dmitrygr 10y ago
Because GC wastes cycles on the user's machines instead of just hiring a competent developer who can manage memory properly. As we move to a more mobile world, wasted cycles matter more. So no. While GC is the definite answer to "how do I allow my dog to make a 'press this button for fart sound' app?" Is it most certainly not the definitive answer (though perhaps a passable one) to "how do I write good fast stable software?"
- ingenter 10y agoYou haven't answered my question. Please re-read it carefully.
- dmitrygr 10y agoI did. You wanted acknowledgement that there are problems for which GC is best solution in C++. I explained why it is never best and likely never anything beyond "barely acceptable".
- ingenter 10y agoDo you understand that the linked article, and the talk referenced in the article describe a way to implement garbage collection as a solution to (memory management for) data structures with cycles? Do you think that this problem is not equivalent to "how do I allow my dog to make a 'press this button for fart sound' app?"? Do you have a better solution to reclaiming data structures with cyclic pointers?
- palunon 10y agoPool allocation, and delete the whole thing at the end. Of course, sometimes (most times ?) you can't do this, and you really need a GC. There is a reason why TAOCP spends a whole chapter on GC IIRC...
- johncolanduoni 10y agoHow does a "good programmer" properly manage cyclical graphs without very specific, static guarantees about how they're used (e.g. All cycles are parent/child)? Because I'd love to know a way to do this without using/implementing the equivalent of a GC.
- adrianratnapala 10y agoIn most of the graph problems I have ever dealt with, the graph is constructed piecemeal but destroyed as a whole after you are finished with it. It is true there are specific problems (e.g git repos) where you want a mutable graph over the long term -- but I have never actually had to deal with those cases, unless it was a special case with a obvious solution (like a doubly-linked list or tree).
- nanolith 10y agoEven in the case of a mutable graph, one can use copy-on-write semantics to create a DAG of graph revisions that can be managed or compacted. I believe this was the strategy used by Subversion. Compaction and collection can both be trivially performed on such a structure by making a deep copy of the latest revision of the graph to a new memory arena, just as is commonly done with a Cheney collector. Old locations are back-patched with pointers to the new locations, which solves the cycle problem.
- gpderetta 10y agohey, that's a generational GC :)
- nanolith 10y agoWell, it's a Cheney GC. To be generational, there would need to be more than two heaps. But, that's hair splitting. Heh. I doubt one would find many C++ folks who would disagree that GC is useful some of the time. It's all about controlling when and where GC is used, which sort of hits home with Sutter's point.