what to do with postblit on the heap?

bearophile bearophileHUGS at lycos.com
Mon Jun 20 08:03:27 PDT 2011


Steven Schveighoffer:

> The other part of this puzzle that is missing is array assignment, for  
> example a[] = b[] does not call postblits.  I cannot fix this because  
> _d_arraycopy does not give me the typeinfo.

This seems fixable. Is it possible to rewrite _d_arraycopy?


> Anyone else have any thoughts?

I think the current situation is not acceptable. This is a problem quite worse than _d_arraycopy because here some information is missing. Isn't this is the same problem with struct destructors?

A solution is to add this information at runtime, a type tag to structs that have a postblit and/or destructor. But then structs aren't PODs any more. There are other places to store this information, like in some kind of associative array.

Another solution is to forbid what the compiler can't guarantee. If a struct is going to be used only where its type is known, then it's allowed to have postblit and destructor. Is it possible to enforce this? I think it is. Here an @annotation is useful to better manage this contract between programmer and compiler.

Bye,
bearophile


More information about the Digitalmars-d mailing list