[fpc-devel] Pascal Smart Pointers Idea + ARC implementation

Sven Barth pascaldragon at googlemail.com
Sat Oct 10 11:25:50 CEST 2015


Am 10.10.2015 11:12 schrieb "Michael Van Canneyt" <michael at freepascal.org>:
>
>
>
> On Sat, 10 Oct 2015, Maciej Izak wrote:
>
>> I am working on smart pointers for FPC (something more than pure ARC for
>> classes).
>>
>> This solution is full compatible with existing code base.
>>
>> I would like to know what do you think about my conception and work.
>>
>> First step is almost done -> new record operators:
>>
>> === begin code ===
>> {$MODESWITCH MANAGEMENTOPERATORS}
>> type // Record with automatic constructor and destructor
>>  TValue = record
>>    class operator Initialize(var aRec: TValue);
>>    class operator Finalize(var aRec: TValue);
>>    class operator Copy(constref aSource: TValue; var aDest: TValue);
>>  end;
>> === end code ===
>>
>> MANAGEMENTOPERATORS are quite simple to implement. MANAGEMENTOPERATORS
were
>> created initially for fast implementation of TValue in RTTI.pas, but they
>> inspired me for smart pointers.
>
>
> This part I understand, it is simple enough. A managed record type ?

I don't think a different type will be needed. Just allow those three
operator overloads for normal records and have them be present in the Init
RTTI of the record so that fpc_initialize(), fpc_finalize() and fpc_copy()
can pick them up. This will be needed anyway should such records be placed
in arrays or other records or classes. (Of course from great power comes
great responsibility ;) )

>
> That would mean that the managed pointer/class would be implemented
internally using a 'managed record', correct ? I like this approach, quite
ingenious :)

It's similar to the approach we use at work in C++. Simplyfies things quite
a bit when one doesn't have to deal with delete ;)

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20151010/1eeb419a/attachment.html>


More information about the fpc-devel mailing list