Re: The D Programming Language
Andrei Alexandrescu (See Website For Email) wrote:
David Abrahams wrote:
Meaning that in Java, all writes of "references" (a.k.a. pointers) are
synchronized?
That is correct. They are guaranteed to be atomic; there is no invalid
reference in Java, ever, period.
For a particular definition of "invalid". As Jean-Marc pointed
out, you can very easily end up with pointers to invalid
objects.
I think you and I basically agree here (based at least partially
on earlier discussions concerning garbage collection). There is
an enhanced degree of safety in Java in this regard. But I
don't like statements like "there is no invalid reference" or
"you cannot leak memory" (which one often hears)---they give a
false sense of security. It's much easier to protect against
accidentally using an invalid object, since the memory
containing the object cannot be used for any other use as long
as there is a pointer to it, but the object may still be
invalid.
In a very real sense, the problem with C++ here isn't that you
cannot have a pointer to an invalid object, it's that a pointer
can suddenly end up pointing to some totally unrelated
object---the memory for a dead object can be recycled while
there are still pointers to it in existance. And that you can
have pointers to non-objects, but in practice, that's less of a
problem, because using such pointers generally results in a core
dump very quickly.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]