[swift-dev] [idle] COW wrapper in 30 lines
Dave Abrahams
dabrahams at apple.com
Thu Mar 10 18:09:03 CST 2016
on Thu Mar 10 2016, Joe Groff <jgroff-AT-apple.com> wrote:
>> On Mar 10, 2016, at 3:54 PM, Dave Abrahams via swift-dev <swift-dev at swift.org> wrote:
>>
>>
>> 2. The thing in your box has to be a value type for this to work. It's
>> pretty uncommon that a thing that's already a value type benefits
>> from being CoW-ified in this way.
>
> It doesn't need to be particularly largeāif your value type contains
> two or more refcounted fields, it becomes cheaper to retain/release a
> single indirect box than to copy around the entire value inline.
You do have to trade that off against the cost of the allocation, but
you make a good point. I'd guess that value instances are probably
copied more often than they're created in other ways.
--
-Dave
More information about the swift-dev
mailing list