On Monday, 25 January 2021 at 10:28:11 UTC, Jacob Carlborg wrote:
On Sunday, 24 January 2021 at 11:00:17 UTC, vitamin wrote:

void destruct(Base base){
void[] x = (cast(void*)base)[0 .. __traits(classInstanceSize, Base)];
    writeln("deallocate: ", x.length);
    theAllocator.deallocate(x);
}

You can get the dynamic size of an object using `typeid(base).initializer.length`.

Base base = new Derived;
assert(__traits(classInstanceSize, Derived) == typeid(base).initializer.length);

--
/Jacob Carlborg

I implementing ref counted pointer with support for weak pointers. Problem was that expired weak pointer can point to already destroyed data => typeid() no longer work or ref type is extern(C) class => typeid() doesn't work.

Reply via email to