John Carmack applauds D's pure attribute

Ben Hanson Ben.Hanson at tikit.com
Tue Mar 6 01:18:25 PST 2012


On Saturday, 25 February 2012 at 22:55:37 UTC, Walter Bright
wrote:
> 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.

The trouble is you don't have to look far to find managed apps
that visibly pause at random due to garbage collection. I've
personally never come across this behaviour with a program that
manages its own memory.

> 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.

Or, you could use std::make_shared().

Given that even C++ struggles to be accepted as a systems
programming language, I can't understand why garbage collection
is used even in the phobos library. If systems programmers think
that C++ has too much overhead, they sure as hell aren't going to
be happy with garbage collection in the low level libraries.

It's an interesting point that hard real-time programs allocate
all their memory up front, mitigating the entire issue, but
obviously this is at the extreme end of the scale.

Regards,

Ben


More information about the Digitalmars-d mailing list