ios理解 -- Pro Mutlithreading and Memory Management for iOS and OS X with ARC, Grand Central Dispatch...

Capturing automatic variables

Next, you need to learn what the “together with automatic (local) variables” part means.
For Blocks, this can be rephrased as “capturing the value of automatic variables.” The
next example shows how thiscapture is accomplished.             

When automatic variables are captured, the values are read-only in the Block. The
variables can’t be modified.

 

Blocks are “anonymous
functions together with automatic (local) variables.

 

isa 

 

A struct for each class is a class_t struct based on objc_class struct. The class_t struct
is declared at runtime/objc-runtime-new.h in the objc4 runtime library.
struct class_t {
struct class_t *isa;
struct class_t *superclass;
Cache cache;
IMP *vtable;
uintptr_t data_NEVER_USE;
};

 

 

一个block的实现是如下:

Next, let’s see the implementation of the anonymous function that uses the Block. The
original Block literal is as follows.
^{printf(fmt, val);}
This is converted to a function.
static void __main_block_func_0(struct __main_block_impl_0 *__cself)
{
const char *fmt = __cself->fmt;
int val = __cself->val;
printf(fmt,

 

转载于:https://www.cnblogs.com/studyNT/p/4474790.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值