zoukankan      html  css  js  c++  java
  • Runtime 中的 _cmd、 IMP

    IMP

    IMP-指向实际执行函数体的函数指针

    #if !OBJC_OLD_DISPATCH_PROTOTYPES
    typedef void (*IMP)(void /* id, SEL, ... */ ); 
    #else
    typedef id (*IMP)(id, SEL, ...); 
    #endif

    可以看到,这个函数体前两个参数是 id(消息接受者,也就是对象),以及SEL(方法的名字)


    method/objc_method

    method - 指向Objective C中的方法的指针

    typedef struct objc_method *Method;

    其中

    struct objc_method {
        SEL method_name                                          OBJC2_UNAVAILABLE;
        char *method_types                                       OBJC2_UNAVAILABLE;
        IMP method_imp                                           OBJC2_UNAVAILABLE;
    }                                                            OBJC2_UNAVAILABLE;

    _cmd

    SEL 类型的一个变量,Objective C的函数的前两个隐藏参数为self 和 _cmd


    Ivar

    ivar - objective C中的实例变量

    typedef struct objc_ivar *Ivar;

    可以看到变量的内存模型

    struct objc_ivar {
        char *ivar_name                                          OBJC2_UNAVAILABLE;
        char *ivar_type                                          OBJC2_UNAVAILABLE;
        int ivar_offset                                          OBJC2_UNAVAILABLE;
    #ifdef __LP64__
        int space                                                OBJC2_UNAVAILABLE;
    #endif
    }                                                            OBJC2_UNAVAILABLE;
  • 相关阅读:
    bzoj 2599
    bzoj 3697
    poj 1741
    bzoj 2741
    bzoj 5495
    bzoj 3261
    网络流24题——骑士共存问题 luogu 3355
    网络流24题——数字梯形问题 luogu 4013
    bzoj 3998
    网络流24题——魔术球问题 luogu 2765
  • 原文地址:https://www.cnblogs.com/junhuawang/p/5760467.html
Copyright © 2011-2022 走看看