On Thursday, 6 February 2014 at 22:16:30 UTC, Dicebot wrote:
On Thursday, 6 February 2014 at 19:01:52 UTC, Brad Anderson
wrote:
Couldn't "scope" allocating a class on the stack just be
considered an optimization that can be applied if the scope
storage class become fully implemented?
I think so. Scope classes were unsafe because of leaking
references but if `scope` is actually implemented to assure
safety it becomes perfectly valid thing to do.
If you declare something as scope, it is expected to have its
destructor called at the end of the scope. Therefore, this
behavior needs to be guaranteed. Theoretically of course, the
memory could still be allocated on the heap and freed after
destruction (or even just marked as destroyed and letting the GC
clean it up), but this will probably not have advantages over
stack allocation, except maybe for large objects.