In this article (http://dlang.org/memory.html) there is an example showing how one could explicitly allocate and deallocate an object. However, the article seems to be sorely neglected and out of date ('delete' is deprecated, right?). Could someone modify the example below using current best practices.

import std.c.stdlib;
import core.exception;
import core.memory : GC;

class Foo
{
    new(size_t sz)
    {
        void* p;

        p = std.c.stdlib.malloc(sz);

        if (!p)
            throw new OutOfMemoryError();

        GC.addRange(p, sz);
        return p;
    }

    delete(void* p)
    {
        if (p)
        {
            GC.removeRange(p);
            std.c.stdlib.free(p);
        }
    }
}

Thanks,
Mike

Reply via email to