ios weak实现原理用的表伪代码

1.伪代码模拟weak用到的主要表

struct weak_referrer_t{
     int weakPtr;//瞎写的不做参考
};

//hash表
struct weak_entry_t{
    int index;
    //存储弱引用该对象的指针的指针的数组
    weak_referrer_t inline_referrers[3];
    id referent;//传入的对象
    int count;
};

//weak_table——hash表
struct weak_table_t{
    //hash数组,用来存储弱引用对象的相关信息weak_entry_t
    weak_entry_t weak_entries[3];
};
struct SideTable {
    //weak_table——hash表
    weak_table_t weak_table;
    
};

//全局的hash表
struct SideTables {
    //全局的hash数组
    SideTable SideTable[3];
    
};

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        
        struct weak_entry_t weak_entry_t1 = {1,[NSObject alloc]};
        struct weak_entry_t weak_entry_t2 = {2,[NSObject alloc]};
        struct weak_entry_t weak_entry_t3 = {3,[NSObject alloc]};
        
        struct weak_table_t weak_table_t;
        weak_table_t.weak_entries[0] = weak_entry_t1;
        weak_table_t.weak_entries[1] = weak_entry_t2;
        weak_table_t.weak_entries[2] = weak_entry_t3;
        
        struct SideTable SideTable;
        SideTable.weak_table = weak_table_t;
      
       };

参照链接:https://blog.csdn.net/u013378438/article/details/82790332

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值