DIP77 - Fix unsafe RC pass by 'ref'

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 9 12:44:37 PDT 2015


On 4/9/2015 11:53 AM, w0rp wrote:
> On Thursday, 9 April 2015 at 18:44:10 UTC, Walter Bright wrote:
>> The only real purpose to a postblit is to support ref counting. Why would a
>> by-value container use a postblit and not ref count?
>
> A struct could have a postblit defined if you are implementing something like
> std::vector, where you you copy the memory when the struct is copied. I'm not
> sure why you would want to do such a thing in D, though.

I'm not sure why you'd do that, either. Just make the memory part ref counted, 
then when modifying it, make the copy then if your ref count > 1.

If you want to interface with std::vector, make opAssign @system, after all, 
you're dealing with C++ :-)



More information about the Digitalmars-d mailing list