[Issue 9433] Deprecate delete
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 31 07:37:23 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9433
rswhite4 at googlemail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rswhite4 at googlemail.com
--- Comment #2 from rswhite4 at googlemail.com 2013-01-31 07:37:20 PST ---
Try this:
[code]
import std.stdio;
void destruct(T)(ref T obj) if (is(T == class)) {
.destroy(obj);
core.memory.GC.free(cast(void*) &obj);
// for valid state
obj = null;
}
void destruct(T)(ref T chunk) pure nothrow if (!is(T == class)) {
core.memory.GC.free(chunk);
}
void main() {
for (int i = 0; i < 1000; i++) {
ubyte[] chunk = new ubyte[40 * 1024 * 1024];
destruct(chunk);
//delete chunk;
}
class A {
ubyte[] _chunk;
this() {
this._chunk = new ubyte[40 * 1024 * 1024];
}
~this() {
writeln("DTor");
destruct(this._chunk);
}
}
for (int i = 0; i < 1000; i++) {
writefln("start #%d run", i);
A a = new A();
destruct(a);
//delete chunk;
writefln("end #%d run", i);
}
}
[/code]
I see no differences if I compare this and delete, except that "delete" looks
nicer.
But I have not made a detailed test, like you did. Maybe you could did the same
with my "destruct".
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list