std.expreimantal.allocator deallocate

Jacob Carlborg doob at me.com
Mon Jan 25 10:28:11 UTC 2021


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




More information about the Digitalmars-d-learn mailing list