Linked by Thom Holwerda on Tue 13th Oct 2009 18:24 UTC, submitted by Lazarus
Permalink for comment 389109
To read all comments associated with this story, please click here.
To read all comments associated with this story, please click here.
News
Linked by Thom Holwerda on 05/22/13 13:38 UTC
Linked by Thom Holwerda on 05/22/13 13:30 UTC, submitted by JRepin
Linked by Thom Holwerda on 05/21/13 22:06 UTC
Linked by Thom Holwerda on 05/21/13 21:45 UTC
Linked by Thom Holwerda on 05/21/13 15:53 UTC
Linked by Thom Holwerda on 05/20/13 22:43 UTC
Linked by Thom Holwerda on 05/20/13 21:50 UTC
Linked by Thom Holwerda on 05/19/13 23:15 UTC
Linked by Thom Holwerda on 05/19/13 23:11 UTC, submitted by Drumhellar
Linked by Thom Holwerda on 05/18/13 21:06 UTC
More News »
Sponsored Links



Member since:
2009-10-14
Theres plenty of info here:
http://clang.llvm.org/docs/BlockImplementation.txt
http://clang.llvm.org/docs/BlockLanguageSpec.txt
Aside from the closure structure, there's a second structure for __block variables (which are shared and mutable). There may also code generated for calling c++ copy constructors/destructors and Objective C retain/release-ing.
Blocks are never magically moved from the stack to the heap. There are two runtime function calls -- Block_copy(block) and Block_destroy(block) -- for managing block lifetime. (Objective C people can use [block copy] / [block release]).
If the block is stored on the stack, Block_copy will copy it to the heap (and return a pointer to the new heap block). Otherwise, it just increments a reference counter.
If you pass your block to a function that keeps it around for later, then it will get copied to the heap (if necessary). C is not doing anything behind your back, though.
Edited 2009-10-14 05:14 UTC