auto classes and finalizers
Sean Kelly
sean at f4.ca
Tue Apr 18 10:22:28 PDT 2006
Don Clugston wrote:
>
> On this topic -- there's an interesting thread on comp.c++ by Andrei
> Alexandrescu about gc and RAII. Among other things, he argues that
> finalisers are a flawed concept that shouldn't be included. (BTW, he
> seems to be getting *very* interested in D -- he now has a link to the D
> spec on his website, for example -- so his opinions are worth examining).
This seems in line with some of the other ideas discussed in this
thread, and with what I'm trying out with this latest release of Ares.
The idea is that the runtime code will be aware of how an object is
being destroyed, be it by by the GC or by some other means. Currently,
that's as as far as it goes unless you want to modify the finalizer
function and rebuild the runtime, but the next release will include a
hookable callback in the standard library similar to onAssertError.
This will allow the user to decide upon which behavior is most
appropriate, and to do so on a per-class basis as I am planning to pass
either the original class pointer or simply a ClassInfo object. For a
debug build it may be appropriate to report the error and terminate (say
via an assert) while some release applications may want to be a bit more
lenient.
This does impose a restriction on standard library code however, as it
must behave as if non-deterministic finalization is always illegal.
This isn't terribly difficult to accomplish, but it's something to be
aware of.
Sean
More information about the Digitalmars-d
mailing list