[fpc-devel] Copy/move operator
Ryan Joseph
genericptr at gmail.com
Wed Jun 19 16:28:11 CEST 2019
> On Jun 19, 2019, at 10:21 AM, Ben Grasset <operator97 at gmail.com> wrote:
>
> Is there any real purpose to implementing `Copy` versus just implementing `operator :=` (or `operator Implicit` when in {$mode Delphi})? Those can be inlined, and in practice are used in essentially all the places `Copy` is. By which I mean, IIRC you never really see calls to `fpc_copy_proc` in the generated assembler unless you've specifically implemented `Copy` yourself.
>
Copy operator is also called with dynamic arrays/open arrays. For example in the code below the copy operator will be called for each of the 3 records. This is why we need a Move operator because if TMyRec.Create allocates memory and then is passed directly to the array we will need to perform another copy when a simple swap would be sufficient (because the records are allocated in temporary memory).
a := [TMyRec.Create(1),TMyRec.Create(1),TMyRec.Create(1)];
Regards,
Ryan Joseph
More information about the fpc-devel
mailing list