GC-free techniques for a wiki page - Was: Smart pointers instead of GC?

Marco Leise Marco.Leise at gmx.de
Mon Feb 3 07:39:22 PST 2014


Am Mon, 03 Feb 2014 12:22:47 +0000
schrieb "Gopan" <gopakumar.gg at gmail.com>:

> Is it possible to switch off GC during compilation so that I will 
> get
> compilation error on every statement that invites GC in?

I would think that parts of druntime/Phobos make use of the GC
at program startup already. And in general any module not on
the compiler command-line when using that switch and with only
a .di file cannot be statically checked.
Even lazy initialization using the GC would not work:

  private Foo foo;

  @property Foo someThreadLocalFoo()
  {
      if (foo is null)
          foo = new Foo;  // <- error
      return foo;
  }

If you compile that module alone or as part of a library, the
compiler has to assume that some other module will eventually
make use of this function.

-- 
Marco



More information about the Digitalmars-d mailing list