StackThreads and Phobos

Bruno Medeiros brunodomedeirosATgmail at SPAM.com
Sun Jul 2 07:42:10 PDT 2006


mclysenk at mtu.edu wrote:
> Hello fellow D users!  I've been working diligently on improving StackThreads
> (http://assertfalse.com), and so far D has worked wonderfully.  The same can not
> be said for Phobos...  (This may get a bit long winded.)
> 
> ---
> 
> 1.  removeRange is really slow.
> 
> In order to prevent the garbage collector from accidentally deleting valid
> objects, we need to mark the stack of each user-context.
> 
> One naive solution is to simply mark the entire stack region, however this isn't
> a very good idea.
> 
> Say I create a user context which calls a function and then yields.  If that
> function performed any allocations, then they would remain on the stack, and get
> scanned by the GC.  Until I overwrite those values, the GC will always see them,
> and therefore never collect their memory. 
> 
> This results in memory leaks, and a dramatic loss of performance.  The solution
> is to dynamically resize the range used by the stack.  When we switch into a
> context, we remove the range, and before we leave, we add it back.  This nicely
> solves the problem, except for one thing - removeRange requires O(n) time.
> 

But isn't that the correct behavior? If one can return to that function 
instance(context), shouldn't all allocations made previously by that 
function remain valid?
(note: I haven't used your library, I just read your post and this 
question came up)
Also: Where do you keep the data from each context? In the heap?


-- 
Bruno Medeiros - CS/E student
http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D



More information about the Digitalmars-d mailing list