DIP68: Adding @nogc to types
Tomer Filiba via Digitalmars-d
digitalmars-d at puremagic.com
Mon Nov 10 04:59:12 PST 2014
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.
-tomer
More information about the Digitalmars-d
mailing list