GC allocation
QAston via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Apr 21 12:37:59 PDT 2016
On Thursday, 21 April 2016 at 17:27:09 UTC, Alex wrote:
> Ok. So, does this mean, that they just allocate on
> creation/binding them? If so, there is no problem and there are
> no questions any more.
Just like classes - when closure expression is executed.
> I have an unusual caption... On creation I capture an immutable
> id for my delegates, which are stored in an array. Indeed, the
> id of the delegate is just the position of it in its array.
> Then, I call my delegate as a function with a parameter,
> depending on it, the call is delegated to another objects (with
> the stored id, of course :) )
> Another possibility, which I could imagine is: not to store the
> id and let the delegate calculate it by some pointer arithmetic
> from the array wherein it is stored. Then, no independent data
> would be stored at all. This would assume however, that
> different function pointers won't be merged, although the one
> and only distinction between them would be the fact of storing
> them at different array indices.
Instead of using a delegate you can use a Struct with opCall.
Pass what you want to copy to the struct by using a constructor
and put your function code in opCall method.
An example here:
https://github.com/QAston/transducers-dlang/blob/master/source/transduced/transducers.d#L797
you can see there various variants of doing the same operation,
using closure, function and struct.
More information about the Digitalmars-d-learn
mailing list