Re: Cancelling dispatch_after?


Quincey Morris
 

On Nov 9, 2017, at 08:57 , Jens Alfke <jens@...> wrote:

because then blocks would always be copied to the heap, even in common cases where they don’t escape

Yes, that sounds correct. I was thinking that there was a problem for the original caller (the one in whose stack frame the block resides), because the block might have moved after the call returns. But (I presume) this could be handled with one level of indirection in the caller, so that it doesn’t care where the block happens to be, plus the passing of a reference to the pointer, so that the pointer can be updated in the event of a (real) copy.

By contrast, in Swift, block (aka closure) parameters are explicitly annotated as escaping or non-escaping, so this kind of hack is avoidable.

Join cocoa@apple-dev.groups.io to automatically receive all group messages.