Is this function pure?

Bill Baxter dnewsgroup at billbaxter.com
Wed Sep 19 12:09:34 PDT 2007


 >> Robert Fraser wrote:
> Someone probably already mentioned this, but you can't (easily, i.e. 
> maybe some sort of heap partitioning could do it but you'd need OS 
> support for that) automatically parallelize functions that allocate 
> memory (since the heap is a shared resource), which was one of the
> big selling points of "pure". So I'm assuming that allocations are
> out of the equation. And since exceptions are most often paired up
> with an allocation (although not necessarily), those might be out,
> too. Not totally sure about that one.
 >
 > There's no reason stack-allocated/scope classes couldn't be used,
 > though.

> Brad Roberts Wrote:
> 
>> Yes you can.  The malloc subsystem out of practical necessity is 
>> internally thread safe and can be used concurrently without concern.

> Robert Fraser wrote:
> Heh, never knew that; that's good news. Thanks for brightening up my day!


On the other hand the support for concurrency may consist of little more 
than a global mutex.  That means that the performance benefits of 
launching multiple threads might not be so great since they'll all just 
end up in a queued waiting for their turn to malloc.

I have no idea what they do in practice though.  Do typical malloc 
systems actually allow simultaneous allocations in multiple threads?

--bb



More information about the Digitalmars-d mailing list