10-Feb-2014 02:25, Jakob Ovrum пишет:
On Sunday, 9 February 2014 at 20:26:20 UTC, Dmitry Olshansky wrote:
I'm saying that basically classes imply infinite lifetime model. Then
you may work extra hard and do things like emplace and manual allocation.
Infinite lifetime is also only with `new`. The "extra work" with emplace
and manual allocation is the domain of library code (e.g. `C c =
alloc!C(ctorArgs);`).
I thought of this for a while and I think lazly dynamic allocation is
still better. First things first - there is still lazy initialization
both ways.
The only potential gain of statically allocating memory here is on the
first exception being thrown, which doesn't gain anything for our prime
case of "many exceptions".
Lastly if the said exception is never thrown, static allocation would
waste more memory of each thread (TLS). This is especially true for
cases where not every thread runs the same code (which is not a small
part of the landscape).
The only issues with using library code instead of `new` are details
like allocation of non-static nested classes and allocation of classes
using private constructors etc.
It is true that classes rely on *uniqueness* to some extent, but
uniqueness is not particular to GC memory.
I'm thinking that I probably should compile this discussion to some
implementable enhancement request for Phobos.
`cachedException` or some such sounds like something suitable for
std.exception.
Thoughts?
--
Dmitry Olshansky