[fpc-devel] Copy/move operator

Sven Barth pascaldragon at googlemail.com
Mon Jun 17 19:00:40 CEST 2019


Ryan Joseph <genericptr at gmail.com> schrieb am So., 16. Juni 2019, 15:29:

> I just came across an efficiency issue when using management operators
> that I’d like to fix before the next release and we have backwards
> compatibility problems.
>
> Basically the problem is that the Copy operator doesn’t know if the source
> value is actually mapped to memory or just a temporary value so we’re
> forced to always copy memory (just to be safe) even when a simple move
> would be good enough. C++ has a similar idea of rvalues and lvalues and a
> copy and move constructor which addresses this.
>
> Here’s a little example of the problem. What I propose is that we either
> add a 3rd boolean parameter to the Copy operator or add a new Move operator
> which is preferred over the Copy operator if it exists (this is much more
> work obviously but maybe has some benefit).
>

If we do this at all we should use a separate operator as those two are
rather different operations and the compiler would already have figured out
which of the two operations is needed and thus the code inside the operator
doesn't need to do that anymore.

That said this would require extending the RTL assignment helper.

And the problems that Jonas mentioned are less problems inside the
compiler, but problems inside the user code when they write their Move
operator incorrectly. From great power comes great responsibility after all
and I'm not sure whether we should provide the users with that much power.

Regards,
Sven

>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20190617/cbf7bd07/attachment.html>


More information about the fpc-devel mailing list