Heap fucntion calls
deadalnix
deadalnix at gmail.com
Wed Sep 21 09:32:49 PDT 2011
D has a wonderfull feature named delegate. Delegate can acess local
data, thus would be dangerous if thoses data were on the stack. For what
I understand, when a delegate can access the local data of a function,
those data are set on the heap instead of the stack, resulting on a
slower function call, but on a safe delegate behaviour.
I'm wondering what's going on behind the hood when such a function is
called. are the parameter passed to the function on the stack and the
copied on the heap ? In such a situation, data are copied two times.
Will a postblit constructor be called two times ? Or is the function
taggued as « heap function » and then only the pointer is passed in the
function call ?
Secondly, how does thing like scope(exit) are handled in such a case ?
When the constext is collected by the GC ? When the function ends it's
execution ? The try {} finally {} analogy suggest the second one, but
this is definitively not an exit of the scope, the scope being still
accsible throw the delegate.
Those are exemple but more generaly, my question isn't about thoses
exemples. It is about what really is going on. Let's say, what would be
the C translation of such a function call or somethung similar.
Thank by adavnce,
deadalnix
More information about the Digitalmars-d-learn
mailing list