[fpc-devel] Management operators AddRef and Copy vs Copy
hnb.code at gmail.com
Sun Apr 10 13:06:28 CEST 2016
Sven proposed that we need to discuss AddRef operator (important part of
smart pointers implementation).
AddRef is used when record is passed as parameter to method/function by
value (for records to large to copy (only the address is pushed)). AddRef
is used also for dynamic array operations (temporary for SetLength
operation and for Copy operation for already copied data by move).
AddRef is much faster than Copy (all data already exist, so we don't need
to copy anything). AddRef is used to increment ref count for managed types.
IMO the best solution is to implement two operators:
class operator AddRef(var aFoo: TFoo);
class operator Copy(constref aSrc: TFoo; var aDst: TFoo);
also is possible to implement single operator:
class operator Copy(aSrc: PFoo; var aDst: TFoo);
aSrc in that case can be nil (for AddRef operation). Anyway that is
Any other solution means big performance loss for RTL operations for
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-devel