> On Jun 19, 2019, at 10:21 AM, Ben Grasset <operato...@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

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to