On 2/25/2012 2:08 PM, Paulo Pinto wrote:
Most standard compiler malloc()/free() implementations are actually slower than most advanced GC algorithms.
Most straight up GC vs malloc/free benchmarks miss something crucial. A GC allows one to do substantially *fewer* allocations. It's a lot faster to not allocate than to allocate.
Consider C strings. You need to keep track of ownership of it. That often means creating extra copies, rather than sharing a single copy.
Enter C++'s shared_ptr. But that works by, for each object, allocating a *second* chunk of memory to hold the reference count. Right off the bat, you've got twice as many allocations & frees with shared_ptr than a GC would have.
