As mentioned here: http://forum.dlang.org/thread/[email protected]#post-ydiprvqyjrqgeahqdbwl:40forum.dlang.org
it would be nice if I could reuse object memory easily. Therefore std.conv 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);
}
----
It would be also nice, if D could add placement-new like C++:
----
Foo f = new Foo(42);
new (f) Foo(23);
----
It looks way more cleaner and since D is aiming to be a system language, reusing memory is a naturally behaviour.