[fpc-devel] Suggestion: reference counted objects

Boian Mitov mitov at mitov.com
Thu Sep 25 01:11:23 CEST 2014

100% agree, although although smart pointers also can already be implemented in Delphi with anonymous methods.
I wanted to mention the possibility actually in my post.
For good smart pointer however we also will need implicit casting, operator overloading and few other features, but it surely is an option.
As for STL, we actually already have implemented some aspects of it in Mitov.Runtime (Free library) for Delphi, and will be doing more.
I am huge fan of STL/boost and the concept based development, and I use some aspects of it even in Delphi (to the extend the language and the generics allow).

With best regards,
Boian Mitov

Mitov Software

From: Nikolay Nikolov 
Sent: Wednesday, September 24, 2014 3:34 PM
To: fpc-devel at lists.freepascal.org 
Subject: Re: [fpc-devel] Suggestion: reference counted objects

On 09/23/2014 08:47 PM, Boian Mitov wrote:

  This is a valid point.
  The only downside is that the object will every time do a deep copy versus a shallow (pointer only) copy. Deep copy is very, very expensive operation.
  Adding ref. counting to objects is probably equivalent of one interlocked assembly instruction, so a very small difference, probably not even measurable.
  Copy of a large object can take a large memory transfer, and will also reserve memory for each copy, thus significantly increasing memory.
  While both approaches have something going for them, they are not total subside for each other.
Yes, but if you have compiler support for objects with automatic calls of constructors/destructor/copy constructor/assignment operator (like in C++ classes), and if you also have generics support for objects, you can make a generic smart pointer object type that adds reference counting to any class. And then the regular class references will serve as weak references. Exactly like C++:


What's more important is that we can extend objects this way, without breaking backward compatibility. But, unfortunately, it's a huge slippery slope from there, as anyone, who has dealt with C++ STL error messages knows:


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140924/c8be96bc/attachment.html>

More information about the fpc-devel mailing list