<div dir="ltr">Thanks, that's clearer.<br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-10-29 5:39 GMT-07:00 Andrei Alexandrescu <span dir="ltr"><<a href="mailto:andrei@erdani.com" target="_blank">andrei@erdani.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 10/28/2015 08:29 PM, deadal nix wrote:<br>
</span><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I think it is very relevent here as destructor is a very common tool to<br>
free resources, as well as one of the most complex to deal with, mostly<br>
because of move semantic. I already had in mind to launch that subject<br>
before this whole thing started.<br>
<br>
Why were things changed that way ?<br>
</blockquote>
<br></span>
On second thought this might inform the best way to go about assigning responsibility for inc/decref across the caller and callee.<br>
<br>
Regarding object copying: we noticed that in C++ it's difficult to define efficient move semantics and forwarding. This is because in a call line<br>
<br>
fun(string("hello"));<br>
<br>
even if fun "consumes" the string by either returning it or forwarding it to another function, the caller of fun must still destroy the rvalue created. In C++1x, if move semantics are at work, there's still a need for the callee to leave the moved-from string in a well-defined state so the destructor doesn't crash. All of that work is unneeded and is required for the sake of that destructor call.<br>
<br>
In D a key element is that objects are relocatable, i.e. they can be moved across memory by using memcpy(). That makes it a more efficient protocol possible:<br>
<br>
1. Caller calls the constructor<br>
2. Object is bibblitted around<br>
3. Object gets destroyed<br>
<br>
So in D, perfect forwarding comes for "free" and we don't need a large feature such as C++'s rvalue references.<br>
<br>
The disadvantage is you can't have value objects with internal pointers. (You can still have reference objects with internal pointers.)<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
Andrei<br>
_______________________________________________<br>
Dlang-study mailing list<br>
<a href="mailto:Dlang-study@puremagic.com" target="_blank">Dlang-study@puremagic.com</a><br>
<a href="http://lists.puremagic.com/cgi-bin/mailman/listinfo/dlang-study" rel="noreferrer" target="_blank">http://lists.puremagic.com/cgi-bin/mailman/listinfo/dlang-study</a><br>
</div></div></blockquote></div><br></div>