[Issue 15009] Object.destroy calls unnecessary postblits for destruction of static arrays object
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Thu Sep 3 14:41:33 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=15009
Kenji Hara <k.hara.pg at gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|Object.destroy doesn't call |Object.destroy calls
|dtors for object in static |unnecessary postblits for
|arrays |destruction of static
| |arrays object
--- Comment #2 from Kenji Hara <k.hara.pg at gmail.com> ---
Note that, destroy actually calls destructors.
import std.stdio, std.conv, core.stdc.stdlib;
struct S {
int x;
this(int x) { writeln("ctor"); }
this(this) { writeln("ctor(postblit)"); }
~this() { writeln("dtor"); }
}
void main(string[] args) {
S[2]* arr = cast(S[2]*)calloc(1, S.sizeof);
printf("-- calloc done\n");
emplace(arr, S(1));
printf("-- emplace done\n");
destroy(*arr);
printf("-- destroy done\n");
//typeid(*arr).destroy(&arr);
free(arr);
printf("-- free done\n");
}
output is:
$ dmd -run test
-- calloc done
ctor
ctor(postblit)
ctor(postblit)
dtor
-- emplace done
ctor(postblit)
dtor
ctor(postblit)
dtor
-- destroy done
-- free done
My point is , the two postblit calls invoked by destroy() is unnecessary.
--
More information about the Digitalmars-d-bugs
mailing list