Purity (D2 standard libraries / object.d)
Denis Koroskin
2korden at gmail.com
Fri Jan 9 20:51:06 PST 2009
On Sat, 10 Jan 2009 07:14:07 +0300, dsimcha <dsimcha at yahoo.com> wrote:
> == Quote from Walter Bright (newshound1 at digitalmars.com)'s article
>> Michel Fortin wrote:
>> > Hum, could the compiler be trusted to add the memoization code to pure
>> > functions so they can stay pure?
>> 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.
>> The problem is identifying if this would be faster than recomputing the
>> return value.
>
> Wouldn't this also cause threading issues? The obvious solution would
> be to use
> TLS, but his requires duplicating the cache across threads. Also, using
> AAs
> internally like this would lead to very deeply hidden memory
> allocations, and
> therefore possibly more frequent GC, etc.
Thread-safe (lock-free?) container would do the trick just fine.
More information about the Digitalmars-d
mailing list