Pure dynamic casts?

Jason House jason.james.house at gmail.com
Tue Sep 22 05:54:14 PDT 2009


Daniel Keep Wrote:

> 
> 
> Jason House wrote:
> > Dynamic casts are pure. They don't use global state, and have the same output for the same reference as input. Interestingly, dynamic cast results are independent of intervening mutable calls... So there's even greater opportunity for optimization.
> 
> What if the GC just happens to re-use that address for a different object?


I was thinking of that and tried to be careful with my wording. I guess I failed. Memoization can't occur, exactly for the reason you indicate. I was trying to say that for the life of an object, the type and type info is immutable. Since a dynamic cast only uses that immutable state, the return value does not change over the lifetime of the object. This could be used for optimizations above and beyond simple purity. 



More information about the Digitalmars-d mailing list