On Thursday, 19 August 2021 at 15:38:19 UTC, evilrat wrote:
On Thursday, 19 August 2021 at 15:12:03 UTC, Ferhat Kurtulmuş

Btw, based on https://github.com/dlang/druntime/blob/master/src/object.d#L4209:

import core.lifetime;
import core.stdc.stdio;
import core.stdc.stdlib;

extern (C) void rt_finalize(void *data, bool det=true) @nogc nothrow; // cheap hack here
alias destroy = rt_finalize;

    class SomeClass
    {
        int a = 42;

        this() @nogc { }
        ~this() @nogc {printf("nogc\n");}
        this(int val) @nogc { a = val; }
    }



    @nogc void main()
    {
SomeClass dynAlloc = cast(SomeClass) malloc(__traits(classInstanceSize, SomeClass));
        dynAlloc = emplace!SomeClass(dynAlloc, 123);
        printf("dynamic %d\n", dynAlloc.a); // 123
        //rt_finalize(cast(void*)dynAlloc);
destroy(cast(void*)dynAlloc); // cast needed :/ dunno consequences though
    }

Reply via email to