On Friday, 16 October 2020 at 03:04:25 UTC, Jack wrote:
How can I allocate memory for this class?
It is possible but not easy without druntime.
If you are using -betterC, you can use extern(C++) classes with
extern(D) members. The compiler will let you declare that. But
then you need to allocate it. `__traits(classInstanceSize,
Whatever)` will tell you the size to malloc, but you also need to
copy an initializer over before you call the constructor.
I have a technique here that works on dmd...
http://dpldocs.info/this-week-in-d/Blog.Posted_2020_07_27.html#zero-runtime-classes
but ldc is more strict about the type definition and I don't know
the magic it expects there... like it should be doable but idk
how so this might not be of much use.
Personally, I prefer to just not use betterC and make my own mini
runtime:
http://dpldocs.info/this-week-in-d/Blog.Posted_2020_08_10.html
in particular
https://github.com/adamdruppe/webassembly/blob/master/arsd-webassembly/object.d#L74
But that's also not easy, lots of unfinished cases in my thing,
but I did manage to make it work... for my specific case.