Purity (D2 standard libraries / object.d)

Michel Fortin michel.fortin at michelf.com
Sat Jan 10 06:45:48 PST 2009


On 2009-01-09 23:14:07 -0500, dsimcha <dsimcha at yahoo.com> said:

> Wouldn't this also cause threading issues?

Well, I'd trust the compiler-generated code would not cause threading 
issues. :-)


> The obvious solution would be to use TLS, but his requires duplicating 
> the cache across threads.

Well, there isn't many choices. Either it's TLS, or the cache need to 
be synchronized (using either locks or lock-free algorithms; both will 
add some overhead anyway).

That said, if you memoize a function member of a class, the memoization 
data could be added to the class and not be global. If the object is 
not shared across threads, then the memoization data isn't either. If 
the object is shared, then you'd need either TLS or synchronization.


> Also, using AAs internally like this would lead to very deeply hidden 
> memory allocations, and
> therefore possibly more frequent GC, etc.

Perhaps the cache needs to be a little smarter than a regular AA. You 
may not want to keep each and every value that was computed. Depending 
on the situation, keeping only the 100 last results may be enough, in 
which case you can dedicate a fixed amount of memory for caching.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list