| >I can't help but notice that C++ community has a strong bias against garbage collection. [...] >Why can't you acknowledge that there are problems that have GC as the only and best solution? Your prelude and the followup question is not well-formed. C++ programmers do not have a bias against GC as a specific problem-solving technique. In fact, expert C++ programmers can embrace GC so much that they can write an entire virtual machine[1] with GC and a DSL[2] for that vm that takes advantage of memory safety. Both the CLR vm and the (original) C# compiler were written by C++ programmers. What the C++ community doesn't want is GC in the C++ base language itself or the standard runtime. That's a very different concept from a generalized "C++ bias against GC". In other words, the following is unacceptable: std::string x = "Hello, " + fullname; // cpu cycles spent on GC
Those cpu cycles spent on constantly checking if "x" is no longer reachable is cpu power that's taken away from rendering frames of a 60fps game, or computing numeric equations or high speed quantitative trading. C++ programmers don't want GC as a global runtime that you can't opt out of. Also, global GC often requires 2x-3x the memory footprint of working memory which is extremely wasteful for the resource constrained domains that C++ is often used in.Herb Sutter's presentation is compatible with "pseudo-GC-when-you-need-it" without adding GC to the entire C++ standard runtime. [1]https://en.wikipedia.org/wiki/Common_Language_Runtime [2]https://en.wikipedia.org/wiki/C_Sharp_(programming_language) |
> std::string x = "Hello, " + fullname; // cpu cycles spent on GC
you are already spending cycles on memory management (if C++ allocates character data on the heap which I think it does). You are searching for free space in the heap, possibly synchronising to do that, and so on.
With a GC you may even use less cycles here! For example a copying GC could mean that you can allocate with a simple thread local bump pointer.
So in your statement you are already paying an unknown cycle cost for memory management. Why do you care if it's GC?
Your answer is probably the variance in the number of cycles - the noticeable pauses - which is a reasonable concern.