[fpc-pascal] C-blocks

Sven Barth pascaldragon at googlemail.com
Fri Nov 16 11:33:33 CET 2018

Am Fr., 16. Nov. 2018, 03:25 hat Ryan Joseph <ryan at thealchemistguild.com>

> > On Nov 15, 2018, at 11:30 PM, Sven Barth via fpc-pascal <
> fpc-pascal at lists.freepascal.org> wrote:
> >
> > No, too many ways to do the same thing don't make things easier, not to
> mention that everything needs to be maintained. So this gets a definite
> "no" from me.
> >
> > Also the overhead for calling an anonymous function is only that for a
> virtual method call.
> Do you mean if the anonymous function has no state it’s only a single
> function call?
> After reading old forum posts it sounded like this was going to be
> implemented by some reference counted structure which was allocated on the
> heap and even using interfaces perhaps. Depending on how this is
> implemented it may not be possible to prevent them from capturing state if
> the anonymous function accesses variables in the parent scope.
> How much of that is accurate?

When a function contains at least one anonymous function then a capture
object is created which is shared by all anonymous functions in the
function and also all captured local variables are moved there. If there is
no variable to capture the capture object is nevertheless created.
The call of an anonymous function is then always a virtual method call
trough the interface VMT of the anonymous function into the capture object.
So if you call an anonymous function multiple times you only have the
overhead of the virtual method call, but only once the impact for creating
the capture object (which might happen in different locations anyway if you
pass an anonymous function outside of its declared scope).


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20181116/51c80f9e/attachment.html>

More information about the fpc-pascal mailing list