Pure dynamic casts?
Daniel Keep
daniel.keep.lists at gmail.com
Tue Sep 22 21:47:02 PDT 2009
Rainer Deyke wrote:
> Daniel Keep wrote:
>> On the basis of how I understand pure to be implemented in D at the
>> moment, it is impure. Purity only considers the bits passed on the
>> stack. If the reference points to the same location in memory, it's
>> considered the same argument.
>
> As I understand it, D doesn't attempt to do general memoization anyway
> (and indeed, shouldn't). Given a reference to an object, if the
> reference itself is not modified from one dynamic cast to another, then
> the result of the former cast can be reused for the latter.
Which is memoisation, more or less.
> The
> existence of the reference prevents the object from being
> garbage-collected, and manual deletion results in undefined behavior.
http://digitalmars.com/d/2.0/expression.html#DeleteExpression
Doesn't actually specify whether this case is kosher or not. I suppose
that makes it undefined behaviour, although possibly not in quite the
same way. :)
More information about the Digitalmars-d
mailing list