[fpc-devel] Management operators AddRef and Copy vs Copy

Maciej Izak hnb.code at gmail.com
Mon Apr 18 13:06:34 CEST 2016


2016-04-18 11:42 GMT+02:00 Anthony Walter <sysrpl at gmail.com>:

> Do the source and dest types need to match?
>

Yes.


> How about:"CopyFrom"? As it is right now you already have type parity
> between types such as floats <- integer and string <- char, so why not
> between TBar <- TFoo?
>
> class procedure TBar.CopyFrom(constref Source: TFoo; var Dest: TBar);
>
> Then this begs question, what's the difference between AutoCopy/CopyFrom
> and:
>
> class operator TBar.Implicit(const Value: TFoo): TBar;
>

Management operators works in different way than standard operators. Any of
management operator is strictly related to RTL code (system.pp), for record
with management operators is exclusively created small kind of VMT for RTL
purposes. In generally set of management operators can't be changed.
Existence of

- class operator Initialize(var aFoo: TFoo);
- class operator Finalize(var aFoo: TFoo);
- class operator [Copy|OtherName](constref aSrc: TFoo; var aDst: TFoo);
- class operator [AddRef|OtherName](var aFoo: TFoo);

is strictly required. That is because:

1. Performance (especially AddRef operator for dynamic arrays - see my
example for Florian)
2. Cooperation with RTL functions like New/Dispose, Initialize/Finalize,
InitializeArray, FinalizeArray, TObject.InitInstance/TObject.CleanupInstance
3. Related to previous point: We need to cover actions for runtime, at
compile time is impossible to cover all usages of records
(like dynamically created instances of records, for example for scripts
purposes).

-- 
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160418/4d7b12ca/attachment.html>


More information about the fpc-devel mailing list