16 ms·
How can you not use manual memory management in C++? Say you're writing a compiler, which uses a quite complex, possibly circular, graph structure of objects fo
by tomp 12y ago
How can you not use manual memory management in C++? Say you're writing a compiler, which uses a quite complex, possibly circular, graph structure of objects for its AST representation. You can't use SharedPtrs (cycles), can't use UniquePtrs (sharing of graph nodes), can't use RAII (unpredictable lifetime). I see no better solution than a GC.
- pjmlp 12y agoWhy can't you use them? Lots of compilers written in C++ use them. Ever heard of weak_ptr?
- maxlybbert 12y agoEven Stroustrup says that there are times garbage collection is the right solution. But, some people are surprised that there are times it isn't needed, and that garbage collection always brings the burden on unordered finalization (e.g., it's possible for an object's members to be finalized before the object, so finalizes must be written in a way that assumes very little about what is valid regarding data members).
- pjmlp 12y agoWhen Java appeared, there GC enabled system programming languages like Modula-3 and Oberon, with stack allocation. Modula-3 generics are good enough to even implement reference counting data structures. The going VM craziness of the last two decades pushed such languages away from the mainstream and thus younger generations get surprised by such approaches.