Should pure functions be prevented from reading changeable immutable static variables?

Don nospam at nospam.com
Sun Nov 7 08:08:33 PST 2010


Michel Fortin wrote:
> On 2010-11-07 01:41:47 -0500, Don <nospam at nospam.com> said:
> 
>> The guarantee of independence is the most important feature. From a 
>> performance point of view, the big win 'pure' gives you comes from 
>> memory management. All memory allocation can be done using a 
>> thread-local memory pool.
> 
> Hum, are you sure about that? If a pure function allocates and returns a 
> string, nothing prevents the non-pure calling function from sending that 
> string to another thread. If that string is allocated from a 
> thread-local pool, what happens?
> 

The return value must be (deep) copied from the memory pool as soon as a 
pure/impure boundary is crossed. Everything else in the memory pool 
should have its finalizer run, if any. Then the memory pool can be 
completely discarded. (No mark/sweep cycle required).


More information about the Digitalmars-d mailing list