On 2009-01-09 22:41:01 -0500, Walter Bright <newshou...@digitalmars.com> said:
If the compiler does general memoization on pure functions, all it has to do is use the bits of the arguments passed on the stack to the function as an index into an associative array of the return values.
True, but only in the absence of pointers to mutable data (pointers to immutable data should be fine). (Hum, and beware of moving GCs, and ignore any memoization data which may be present inside the arguments... isn't determining equality a job for opEquals?)
The problem is identifying if this would be faster than recomputing the return value.
That's why I was using a "memoized" attribute in the function declaration, so the programmer decides if this function needs memoization or not. I know it's often a tough decision even for the designer of a function, but if adding memoization becomes easy, as a library designer you could just not worry about it and let users create a memoization wrapper when necessary.
-- Michel Fortin michel.for...@michelf.com http://michelf.com/