It seems that D has currently no direct support to reuse object memory.
D should add a new-placement syntax:
----
Foo f = new Foo(42);
new (f) Foo(23);
----
and/or should add an emplace overload which takes an object:
----
T emplace(T, Args...)(ref T obj, auto ref Args args) if (is(T == class)) {
    if (obj is null)
        return null;

    enum size_t ClassSize = __traits(classInstanceSize, T);
    void[] buf = (cast(void*) obj)[0 .. ClassSize];

    import std.conv : emplace;
    return emplace!(T)(buf, args);
}
----

Reply via email to