[fpc-devel] Suggestion: reference counted objects
Chriss Kalogeropoulos
iz.iznogood at gmail.com
Sat Sep 20 19:47:41 CEST 2014
Hello all,
Instead of hardcoding stuff into the (amazing) fpc compiler, would it be
possible to use generics and operator overloading to create a smart pointer
implementation?
This might require some improvements like record constructors/destructors
(or initializer/finalizer) and some way to overload the member access
operator "." but it might create a more flexible and powerful
implementation.
Chriss
Στις 20 Σεπ 2014 6:41 μ.μ., ο χρήστης "hinstance at yandex.ru" <
hinstance at yandex.ru> έγραψε:
> Link to Lazarus forum thread with reference counting discussion:
> http://forum.lazarus.freepascal.org/index.php/topic,22231.0.html
> My opinion: yes, this feature should be implemented.
>
> And yes it should be optional (either additional root object or local
> compiler switch), so that existing code could remain unmodified.
>
>
> 20.09.2014, 19:00, "Hans-Peter Diettrich" <DrDiettrich1 at aol.com>:
>
> Sven Barth schrieb:
>
> On 20.09.2014 12:36, Hans-Peter Diettrich wrote:
>
> AFAIK some Delphi XE made TObject itself managed, by reference counting.
> It would be easy to introduce the same feature in FPC, so that no
> special base class would be required. Like with extended RTTI a decision
> should be made, whether managed objects should be enabled or disabled by
> default. Afterwards automatic management can be turned on or off for
> every single class or object individually.
>
> It's basically easy, yes, but then one has to deal with code like this:
>
> [...]
>
> Which could lead to some unintended side effects if "o" is passed to
> some other code which keeps the instance around and ".Free" merely
> decreases the reference count. Of course that would have been a memory
> leak before and now it's not, but nevertheless it changes behavior.
>
> I already mentioned that destructors still are required, but will have
> an different purpose and usage than before. This would discourage
> continued use of Destroy(), BeforeDestruction() etc., which should at
> least be renamed to prevent unconverted legacy code from compiling. This
> change already will break compatibilitiy, so that consequently all
> libraries (in detail when dealing with lists containing objects) have to
> be updated. I was aware of such consequences, but I'm no more sure of
> the consequences of my idea of simply turning refcounting on or off for
> specific objects or classes.
>
> The mere implementation of refcounting for TObject is easy, but the
> consequences are hell :-(
>
> DoDi
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
>
> _______________________________________________
> fpc-devel maillist - fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140920/119a8f11/attachment.html>
More information about the fpc-devel
mailing list