how to allocate class without gc?

Guillaume Piolat via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 26 07:12:55 PST 2016


On Tuesday, 26 January 2016 at 13:56:39 UTC, Igor wrote:
>
> //ubyte[__traits(classInstanceSize, App)] buffer;
> auto buffer = 
> core.stdc.stdlib.malloc(__traits(classInstanceSize, 
> App))[0..__traits(classInstanceSize, App)];
>
> works, so it is the ubyte line.
> 		

Make sure the buffer outlives the class instance.
If you emplace on the stack, then at the end of the scope your 
instance is gone.


More information about the Digitalmars-d-learn mailing list