> On Jun 17, 2019, at 2:19 AM, Jonas Maebe <jo...@freepascal.org> wrote: > > And which also causes hard-to-find memory corruption bugs.
How so? I looked into this yesterday and it’s pretty easy to tell if a node is temporary memory or not, but if there’s a chance it isn’t then calling the copy operator is still safe. > >> 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). > > The compiler knows that source is a temporary value that will be gone > afterwards, so it could perform this optimisation itself in this case. It > won't be possible to always do this and there are undoubtedly cases where a > dedicated Move operator would result in more optimal code, but > maintainability and safety are also important. If the compiler knows the source is temporary then why can’t the copy operator be told of this? This is specifically for the new management operators (which are always called) so the compiler can’t make any optimizations here anywhere. Seems like an obvious win to me to gain some performance and avoid unnecessary copies. Regards, Ryan Joseph _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel