When to call GC.{add,remove}Range in containers?

Nordlöw via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Oct 10 00:12:10 PDT 2016


Which std.trait should be used to statically check whether I 
should call GC.{add,remove}Range on the elements of D containers?

`std.container.array.Array` currently uses `hasIndirections` but 
a comment on the same line says it should use `hasPointers` 
instead.

containers-em uses

template shouldAddGCRange(T)
{
	import std.traits;
	enum shouldAddGCRange = isPointer!T || hasIndirections!T || is 
(T == class);
}

Quite some inconsistency here.

And what the case `Array!(Array!int))`? The wrapper Array!int 
contains contains a non-GC allocate pointer to ints and should 
not be scanned by the GC. Do we need another Container-trait for 
this? Or do we need to tag pointers with a special attribute that 
tells whether it has been allocated by GC or not.



More information about the Digitalmars-d-learn mailing list