search

Home  >  Q&A  >  body text

ios - oc实例对象的实例成员的数据存在哪里 objc_ivar ?objc_object?

类的定义

struct objc_class {
    Class isa;

    Class super_class;
    const char *name;
    long version;
    long info;
    long instance_size;
    struct objc_ivar_list *ivars;
    struct objc_method_list **methodLists;
    struct objc_cache *cache;
    struct objc_protocol_list *protocols;
}

struct objc_ivar {
    char *ivar_name;
    char *ivar_type;
    int ivar_offset;
}                

struct objc_ivar_list {
    int ivar_count;
    /* variable length structure */
    struct objc_ivar ivar_list[1];
} 

ivars 列表存放的是字段的定义?

实例的定义

typedef struct objc_object {
    Class isa;
} *id;

只有一个成员(指向所属类的指针),那他的字段数据放在哪里呢?

PHPzPHPz2890 days ago295

reply all(1)I'll reply

  • ringa_lee

    ringa_lee2017-04-17 18:01:13

    The object initialization data is placed in the heap. The member variable pointers of the instance object are all in objc_ivar_list * ivars. The object finds the corresponding memory and accesses the data through the pointer. Do you understand this?

    reply
    0
  • Cancelreply