DIP68: Adding @nogc to types

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 10 12:00:21 PST 2014


On 11/10/2014 4:59 AM, Tomer Filiba wrote:
> http://wiki.dlang.org/DIP68
>
> This DIP proposes the addition of a compiler-enforced @nogc attribute on types.
> This means means such a type cannot be allocated by the GC, e.g., using operator
> new on such a type or appending such a type to a dynamic array, would result in
> compile-time errors.
>
> It enforces separation between deterministic and non-deterministic finalization
> and lifetime of objects, which is crucial for proper RAII idiom.
>
> For instance, suppose you require deterministic finalization of some resource,
> which is encapsulated by a struct whose destructor *must* be called. If your
> users could (accidentally?) create this object in the GC heap (e.g, holding it
> in an AA), you lose all RAII guarantees and break the code's assumptions.

I'm not at all sure that how a type is allocated should be part of the type 
itself. There are an infinite way things can be allocated.



More information about the Digitalmars-d mailing list