Newbie initial comments on D language - scope
Walter Bright
newshound1 at digitalmars.com
Sat Feb 2 12:42:00 PST 2008
Edward Diener wrote:
> The idea in my mind is essentially that 'scope' classes automatically
> define an object that, when used exactly as an normal GC object,
> automatically calls the destructor of the object just as soon as the
> last reference to it goes out of scope. In this sense the user neither
> know or cares whether the object encapsulates a resource or not and uses
> an object of such a class just as he would use any other GC object.
> Similarly the user can force an object to be a 'scope' object through
> the second syntax give above, but from then on he treats the object just
> as he would any other GC object.
The problem is:
scope C c;
C d;
d = c;
and now d is no longer properly ref-counted. The 'scopeness' of an
object must therefore be part of its type. The assignment d=c would have
to be illegal.
> Please take a look at atomic operations, which I am sure you already
> know about. I believe boost::shared_ptr<T> in its latest incarnation is
> using it to increment and decrement the reference count without the
> usual time penalty which you mention.
There has been a lot of work done improving atomic operations. That's
one reason for making it a library feature - the library stuff can be
improved without having to change the compiler.
More information about the Digitalmars-d
mailing list