Bug 14470 – Reuse of object memory: new emplace overload

Status
NEW
Severity
enhancement
Priority
P4
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-04-20T07:12:30Z
Last change time
2024-12-01T16:24:22Z
Assigned to
No Owner
Creator
rswhite4
Moved to GitHub: phobos#10127 →

Comments

Comment #0 by rswhite4 — 2015-04-20T07:12:30Z
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.
Comment #1 by rswhite4 — 2015-04-26T21:14:13Z
Comment #2 by robert.schadek — 2024-12-01T16:24:22Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/phobos/issues/10127 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB