Rick said:
My question is.. if Lisp, a 40 year old language supports garbage
collection, why didn't the authors of C++ choose garbage collection for
this language? Are there fundamental reasons behind this? Is it because
C is generally a 'low level' language and they didn't want garbage
collection to creep into C++ and ruin everything?
I guess the principle is not to take decisions about things like memory
management out of the programmer's hands ... C++ was designed to stay pretty
much as efficient as C. There is also a principle of "extensibility via
libraries" instead of adding features to the language (if you want a garbage
collector, you can always add one; the "new" operator was made overloadable
so that memory management could be done however you like). The disadvantage
is that some things would be much easier to use if they were built into the
language, eg. a "for each ..." statement (with a local body that allows
break & continue), a completely polymorphic type (like the "any" type in the
boost library), and (optional) garbage collection.
Here are some web pages related to garbage collection in C++:
http://www.hpl.hp.com/personal/Hans_Boehm/gc/index.html
(lots of garbage collection resources)
http://www.jelovic.com/articles/cpp_without_memory_errors_slides.htm
(a "safe pointer" type)
- neither of which I have actually tried, but they look good ...
I also read about a library which lets you group a set of objects together
and free them all at once (much faster than one at a time), but I can't find
it right now. Has anyone else heard of this library ?
David F