Re: SGCL - Garbage Collector for C++
On Mar 3, 6:27 am, Kai-Uwe Bux <jkherci...@gmx.net> wrote:
Sam wrote:
James Kanze writes:
[snip]
[snip]
collection is essential in Java, because all objects must be
allocated dynamically, and user defined types can't have value
semantics. It's optional in C++, because we do have value
semantics. Optional, but it still saves the programmer some
unnecessary work.
No, it's not "optional" in C++. It does not exist, at all,
in C++. Go look up the "optional" part of ISO/IEC 14882:2003
that defines whatever you think "garbage collection" means
in the C++ context. I eagerly await the results of your
search.
I don't think that is entirely correct.
It's not correct at all. However...
The C++ standard is worded very cautiously with regard to new
and delete to leave a tremendous amount of freedom to the
implementation. I think, a compliant implementation could use
garbage collection. In particular, I do not know of any
language in the C++ standard that would require the following
program to ask the execution environment for an unbounded
amount of memory:
int main ( void ) {
while ( true ) {
new int ( 5 );
}
}
There are a few legal constructs in C++ which do cause problems
with garbage collection. (They don't occur in any reasonable
real programs, but they are formally there.) When I said it was
"optional", I was thinking in terms of the way threading is
optional. The standard doesn't really define it, and you do
need to fudge a few things to make it fit, but in practice, it's
available to anyone that wants it, and it's actually widely used
in C++ applications already. Just like threading.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34