Linus with some good observations on garbage collection

Timon Gehr timon.gehr at gmx.ch
Fri Apr 22 21:58:17 PDT 2011


Ulrik Mikaelsson wrote:
> All in all, I think the best approach is a pragmatic one, where
> different types of resources can be handled according to different
> schemes.
>
> I.E. default to GC-manage everything. After profiling, determining
> what resources are mostly used, and where, optimize allocation for
> those resources, preferably to scoped allocation, or if not possible,
> reference-counted.
>
> Premature optimization is a root of much evil, for instance, the
> malloc-paranoid might very well resort to abuse of struct:s, leading
> either to lots of manual pointers, or excessive memory copying.
>
> Incidentally, this was the main thing that attracted me to D. Be
> lazy/productive where performance doesn't matter much, and focus
> optimization on where it does.

That is very true. GC is almost always fast enough or even faster. And it is
clearly most convenient. And yes, identify bottlenecks first, optimize later. But
I also think programs that have some concern about efficient memory allocation
(with GC or without GC) tend to be better designed in general. This actually
increases productivity. Plus, it reduces the need for complicated optimizations
later on. This in order increases maintainability.

-Timon


More information about the Digitalmars-d mailing list