A bug in my code

Sergey Gromov snake.scaly at gmail.com
Mon Sep 8 02:44:14 PDT 2008


Bill Baxter <wbaxter at gmail.com> wrote:
> On Mon, Sep 8, 2008 at 8:33 AM, bearophile <bearophileHUGS at lycos.com> wrote:
> > Jarrett Billingsley:
> >> There's no way to do it with any heap-allocated value, which does seem
> >> a bit like a hole to me.
> >
> > I think there's both a syntax problem (what syntax to use?), and the fact that when possible D wants to avoid programming mistakes, so it wants to initialize memory to a clean state (this is even more important for the GC).
> 
> > But maybe this isn't important enough.
> 
> Yeh, maybe not this one thing.  But enough grains of sand like this
> and you have a sizable obstacle.  And D has a fair number of such
> grains.

A non-initialized array must never be scanned for pointers, even if the 
underlying type contains them.  This is a very dangerous feature which 
must not be available in SafeD.  You can always use

  T[] allocArrayNoInit(T)(size_t count) {
    void[] mem = std.gc.malloc(count * T.sizeof);
    std.gc.hasNoPointers(mem.ptr);
    return cast(T[])mem;
  }


More information about the Digitalmars-d-learn mailing list