On Fri, 07 Jun 2013 19:50:58 -0400
Toby Thain <toby at telegraphics.com.au> wrote:
[C++]
apparently gained
some form of closure recently but it remains unclear how a lexical
closure is reliably implemented without proper gc
Well. As allways with C++: It
leaves the decision up to the programmer.
This way the programmer can, well should, must, choose what way that is
most efficient for the given situation. You can "plug in" a full blowen
garbage collector to manage your memory. Or use smart pointers as a
simple, primitive variation of gc. (... that works so well in many
situations that a full blowen garbage collector is unnecessary many
times.) You can pass the "lexical scope" by value, i.e. make a copy at
the time the lambda is instantiated. (You may say that this defetas the
purpose of lambdas. But actually it is the proper solution in many
situations.) Or you can pass by reference. But in the later case you
have to ensure that the reference is still valid when the lambda is used.
That is the point about C++: If a language offers only one, single
mechanism for a task, like garbage collection for memory management, it
forces the programmer to this singe way. Even in situations where this
one, single machanism is not apropriate. C++ deliberately gives you the
choice of many ways. - And thus the responsibility to use your brains
to find the way most efficient way for the speciffic, given task at
hand.
Thats why I dont like e.g. Java. It imposes garbage collection on me
even where not appropriate or unwanted, making very usefull things like
RAII de facto impossible.
--
\end{Jochen}
\ref{http://www.unixag-kl.fh-kl.de/~jkunz/}