On 25/02/2012 22:55, Walter Bright wrote:
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.

http://www.boost.org/doc/libs/1_43_0/libs/smart_ptr/make_shared.html

so you don't have to have twice as many allocations.

--
My enormous talent is exceeded only by my outrageous laziness.
http://www.ssTk.co.uk

Reply via email to