Prevent Garbage Collector
Adam D. Ruppe
destructionator at gmail.com
Sat Jan 4 10:27:18 PST 2014
On Saturday, 4 January 2014 at 17:37:00 UTC, Jeroen Bollen wrote:
> Would that work with structs too?
>
> Struct* i = malloc(Struct.sizeof);
> i = &Struct(params);
You don't want to take the address of a temporary, not with
structs nor int. But you could copy it with *i = Struct(params)
and that should be ok. There's also std.conv.emplace that might
be useful.
And bearophile is right too, of course, that it will need a cast
on malloc.
Struct* i = cast(Struct*) malloc(Struct.sizeof);
More information about the Digitalmars-d-learn
mailing list