UDA and trait for non-GC managed pointers

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat Oct 15 10:11:28 PDT 2016


On 10/15/2016 12:22 PM, Nordlöw wrote:
> Is there a way to check if a pointer is supposed to point to non-GC
> allocated memory? I presume not. This is needed to prevent unnecessary
> calls to `GC.addRange` in containers with elements of a type that in
> turn is a container-like struct with non-GC allocated memory.

I don't know of a simple way.

> If not, maybe we could tag those non-GC-mangaged pointers with a UDA,
> preferrably `@nogc`, and then build a trait, say, `hasGCIndirections`
> that doesn't include @nogc-pointers.
>
> What do you think?

Seems there'd be quite some annotational overhead. Some experience would 
be welcome.


Andrei


More information about the Digitalmars-d mailing list