[D-runtime] GC to track external memory?

Sean Kelly sean at invisibleduck.org
Fri May 27 10:24:41 PDT 2011


Why is this needed?  And FWIW this should be possible today by creating a class that references this memory and calls free() or whatever in its dtor.

On May 22, 2011, at 3:38 AM, Michel Fortin wrote:

> I'd like to add a feature to the GC allowing it to track externally-allocated memory. The simplified use case is this:
> 
> 	struct S { ... }
> 	extern (C) S* s_create();
> 	extern (C) void s_destroy(S*);
> 
> 	void main() {
> 		S* s = s_create();
> 		GC.track(s, S.sizeof, &s_destroy, false/*no scan*/);
> 		...
> 	}
> 
> By calling "GC.track", the GC would start tracking pointers pointing to the specified memory block during the mark phase and then call the "s_destroy" function as the finalizer when it is no longer reachable. I looked at how the GC works, and one idea that pops to mind is to add special Pool that would cover pages corresponding to those external objects, a Pool that would be created as needed when adding external blocks through "GC.track" and that would not be available for allocation.
> 
> I realize this solution makes it be impossible to track blocks at a finer granularity than aligned 16 bytes, but I can live with that constrain.
> 
> Does this approach makes sense? any concern? any better idea?
> 
> -- 
> Michel Fortin
> michel.fortin at michelf.com
> http://michelf.com/
> 
> 
> 
> _______________________________________________
> D-runtime mailing list
> D-runtime at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/d-runtime



More information about the D-runtime mailing list