block类型

2021-05-06  本文已影响0人  Berning

非ARC环境block类型

//非ARC
      void(^block)(void) = ^{
          NSLog(@"hello");
      };    //__NSGlobalBlock__
   
//非ARC
    int a = 10;
    
    void(^block)(void) = ^{
        NSLog(@"hello:%d",a);
    };  //__NSStackBlock__

//非ARC
    int a = 10;
    void(^block)(void) = [^{
        NSLog(@"hello:%d",a);
    } copy];    //__NSMallocBlock__

ARC环境block

ARC环境下编译器会根据以下情况将栈区block复制到堆区

property属性

对象类型的auto变量

static void __main_block_copy_0(struct __main_block_impl_0*dst, struct __main_block_impl_0*src) {_Block_object_assign((void*)&dst->p, (void*)src->p, 3/*BLOCK_FIELD_IS_OBJECT*/);}

static void __main_block_dispose_0(struct __main_block_impl_0*src) {_Block_object_dispose((void*)src->p, 3/*BLOCK_FIELD_IS_OBJECT*/);}

static struct __main_block_desc_0 {
  size_t reserved;
  size_t Block_size;
  void (*copy)(struct __main_block_impl_0*, struct __main_block_impl_0*);
  void (*dispose)(struct __main_block_impl_0*);
} __main_block_desc_0_DATA = { 0, sizeof(struct __main_block_impl_0), __main_block_copy_0, __main_block_dispose_0};

上一篇 下一篇

猜你喜欢

热点阅读