Reuse object memory?
Namespace via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Apr 19 15:27:58 PDT 2015
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);
}
----
More information about the Digitalmars-d-learn
mailing list