Allocating structs with new?
Robert Jacques
sandford at jhu.edu
Sat Jul 10 18:49:33 PDT 2010
On Sat, 10 Jul 2010 18:17:21 -0400, Leandro Lucarella <luca at llucax.com.ar>
wrote:
> Robert Jacques, el 10 de julio a las 02:31 me escribiste:
>> As for the bug, it's actually somewhat old. Issue 2834 was filed
>> back in April of 09 - Struct Destructors are not called by the GC,
>> but called on explicit delete. And this is a bug in the spec, not
>> DMD; the only way to run struct destructors from the GC is to add
>> vtables to them or hidden in the GC (i.e. to make them classes).
>
> You don't need a vtable, because you don't have inheritance with
> structs. All you need is a function pointer pointing to the finalization
> function/method. This plays well with the concept of having type
> information associated to blocks of memory in the GC, which means
> (semi)precise heap scanning. So maybe is not a bad idea to make the
> destructors of structs get called by the GC :)
>
:) That's sort-of what I meant by a vtable. (Either it being one function
or an actual table so structs could hook into the class finalization
method.)
More information about the Digitalmars-d
mailing list