Kevin McGuire wrote:But, I think that there are some advantages to GC performance wise in at least select cases. I do not know if there are any practical applications of this.
It's not so much practical applications of fast GC as it is identifying the circumstances in which GC is faster than manual memory management. A typical stop & copy generational collector like the one used by the CLR can allocate memory very quickly, and there is very little space overhead for tracking each object. For code that allocates many small objects frequently, this is more efficient than typical "unmanaged" heap allocation. Deallocation can take about as long as handling a page fault, which is not good for real-time applications, but otherwise the cost is negligible and is amortized over the many (and much faster) allocations.
mystran wrote:In all seriousness, properly followed RAII and correct use of auto_prt will make that goal quite a bit more tractable, so it's a lot easier in C++ than almost any other language.
Oh, I agree. RAII is great, and IMO all languages should have it -- at least for non-memory resources, if not for memory management.
There are at least two problems with manual memory management though, even with RAII -- dealing with cyclical data structures, and implementing non-trivial
lock-free algorithms -- hazard pointers are not easy to understand IMO.
I'll give you an example of a problem with the first case that I'm having right now. I'm working on a component that internally keeps track of many things using a highly-connected object graph (I'm afraid I can't be very specific here). In particular, many objects in this graph have parent-child logical relationships and bi-directional links between them. The problem is, any thread can try to insert and remove nodes from this graph at any time in such a way that the insertion or removal of an entire group of nodes at once must be atomic. Trying to manage the lifetime of the graph nodes in a thread-safe manner during operations that might affect many nodes at once is very non-trivial! Especially when the links are necessarily non-symmetric -- some will be shared_ptrs, and some will have to be weak_ptrs. GC would at least remove one concern from this particular Gordian knot.