On 4/15/2011 5:01 PM, Sean Kelly wrote:
On Apr 15, 2011, at 1:12 PM, Don wrote:
Create a pure heap for each thread. This is a heap which can only be
used by pure functions. I present some simplistic code, with the
simplest possible implementation: just a big block of memory with a thread
local 'stack pointer' which points to the first free slot.
It's a good idea. dsimcha was already going to polish his TempAlloc, wasn't
he? Seems like this is nearly the same thing.
Yeah, I never formalized it at all, but that's roughly what TempAlloc
accomplishes. My other concern is, what happens in the case of the
following code:
uint nonLeaky() pure {
foreach(i; 0..42) {
auto arr = new uint[666];
// do stuff
}
return 8675309;
}
In this case the arr instance from every loop iteration is retained
until nonLeaky() returns, whether it's referenced or not. Granted, this
is a silly example, but I imagine there are cases where stuff like this
happens in practice.