[fpc-devel] Suggestion: reference counted objects

Ewald ewald at yellowcouch.org
Sat Sep 20 14:15:41 CEST 2014


On 09/20/2014 01:42 PM, Sven Barth wrote:
> On 20.09.2014 13:11, Peter Popov wrote:
>> Please do not reference count TObject. This is a uniquely bad and
>> unnecessary idea. I will switch to ANSI C if you guys do it
>
> Please enlighten me why you think it is bad. Give reasons and don't be
> like "a farmer doesn't eat what he doesn't know" (rough translation of
> a German proverb).

I think I have a reason.

First off, I do like refcounting: I use it a lot, *where useful*.

To make TObject refcounted would mean that everything is all of the
sudden refcounted, what:
    - Changes the current behavior of classes (bye bye backward
compatibility)
    - Adds performance overhead to every assignment between classes:
            a {TObject}:= b {TObject}; // Currently the same as a
{Pointer}:= b {Pointer};

        becomes

            b.IncRefCount;
            a.DecRefCount;
            a's Pointer to instance:= b's Pointer to instance;

        Throw in the handling of race conditions between threads and the
entire thing becomes bloated IMO.
   
    - Won't allow the user to cast to and fro between classes and
pointers (useful to pass the classes thru an external API back to a
pascal callback)

What would be handy is a seperate root class that is always refcounted,
something like TRefcountedObject or something. On the other hand some
directive that makes this class refcounted would also be a good solution
IMO (something that works for refcounting in the same way as $M does for
RTTI).

Just my 5 cents.

-- 
Ewald





More information about the fpc-devel mailing list