RFC: naming for FrontTransversal and Transversal ranges

Robert Jacques sandford at jhu.edu
Thu Apr 30 21:10:18 PDT 2009


On Thu, 30 Apr 2009 23:18:13 -0400, Rainer Deyke <rainerd at eldwood.com>  
wrote:
> Robert Jacques wrote:
>> On Thu, 30 Apr 2009 17:23:19 -0400, Rainer Deyke <rainerd at eldwood.com>
>> wrote:
>>> It's possible to write a reference wrapper around a value type.  It's
>>> also possible to write a value wrapper around a reference type.
>>> However, the former is both easier and more efficient than the latter.
>>
>> Yes and no. Yes, the deep copy mixin is more complex to write the first
>> time, but after that it's easy to use. And second, it's just as
>> efficient as the later, since the deep copy mixin generates the same
>> code as a value type.
>
> A simple deep-copy struct wrapper around a class type is horribly
> inefficient compared to a direct struct type:

Reference semantics don't require classes. D arrays have reference  
semantics, but are implemented as structs. Phobos could do something  
similar.

>   - It uses an extra heap allocation per instance.

And during a deep copy, you're often making a lot of heap copies. (N vs  
N+1 when N>>1)

>   - It uses an extra level of indirection.
>   - It uses virtual function calls.

Not if the class is final.

>   - It allocates an extra reference to a virtual function table per
> instance.

Huh? Isn't that part of the extra heap allocation?

Also, a really important question is: is it possible to implement are  
shared, lock-free containers as value types?




More information about the Digitalmars-d mailing list