[fpc-devel] Improving Ref Counting

DrDiettrich drdiettrich at compuserve.de
Mon Feb 28 07:06:21 CET 2005

Uberto Barbini wrote:

> > You already have them in Iunknown, ansistrings and variants. Its all a
> > question of making them faster cause they are dog slow atm.
> I wish them "NOT" managed, you cannot free a interface in Delphi.

You can finalize it, so that it releases all private resources. That's
common practice in a GC environment. But then you are responsible when
the interfaced object is referenced from one of the still remaining
references, and it fails to act properly due to the missing resources.

> Anyway, why you're saying that refcount is slow? Do you have any benchmark?
> If I recall you mentioned try..finally as the bottleneck, but AFAIK modern cpu
> should do it almost with zero overhead, differently from try..except.

Please separate the overhead in normal operation from the overhead in
exception handling. We had a lengthy thread about exception handling in
a Delphi group, with interesting results. I don't know how exactly FPC
implements Try blocks, but there shouldn't be much room for
implementations very different from the Delphi (Windows) implementation.

In normal operation a Try block requires to push and pop some pointers,
comparable to the argument handling of a subroutine call. The invocation
of the Finally code may cost a few extra cycles, because it has to be
executable both in normal and abnormal program flow. The Exception code
executes only when an exception occurs, so it does not add any time
penalty in normal operation. Consequently one should eliminate chances
for exceptions, not try/except/finally blocks ;-)


More information about the fpc-devel mailing list