Objective-C underlying data structure
Objective-C underlying data structure
Objective-C underlying data structure
Class Data Structure
Class (pointer)
Typedef struct objc_class * Class;/* this is the data structure generated by the compiler for each Class. This structure defines a Class. this structure is generated by the compiler during execution and used to send messages during runtime. therefore, some members change the type. the compiler generates a "char * const" string pointer instead of the following member variable "super_class" */struct objc_class {struct objc_class * class_pointer;/* pointer to the metaclass. */struct objc_class * super_class;/* pointer to the parent class. NSObject is NULL. */const char * name;/* class name. */long version;/* unknown. */unsigned long info;/* bit mask. refer to the mask definition of the following class. */long instance_size;/* number of bytes of the class. includes the definition of classes and all parent classes */# ifdef _ WIN64 long pad; # endif struct objc_ivar_list * ivars;/* points to the list structure of instance variables defined in the class. NULL indicates that no instance variable exists. does not include the variables of the parent class. */struct objc_method_list * methods;/* The instance method defined in the Link class. */struct sarray * dtable;/* points to the instance method allocation table. */struct objc_class * subclass_list;/* parent class list */struct objc_class * sibling_class; struct objc_protocol_list * protocols;/* Target prototype list */void * gc_object_type ;};
Method (pointer)
Typedef struct objc_method * Method;/* the compiler generates one or more such structures for the class based on the methods defined in the class. the implementation of a class can be dispersed in different parts of a file, and classes can be dispersed in different modules. to solve this problem, use a separate method linked list */struct objc_method {SEL method_name;/* this variable is the name of the method. the compiler uses a 'Char * 'here. When a method is registered, the name is replaced by a real SEL */const char * method_types during runtime; /* List of parameters used to describe the method. used when the selector is registered at runtime. at that time, the method name will contain a list of parameters of the method. */IMP method_imp;/* address of the method execution. */};
Ivar (pointer)
Typedef struct objc_ivar * Ivar;/* the compiler generates one or more such structures for the Class Based on the instance variables defined in the class */struct objc_ivar {const char * ivar_name; /* variable name defined in the class. */const char * ivar_type;/* describes the variable type. debugging is very useful. */int ivar_offset;/* base address offset byte of the Instance structure */};
Category (pointer)
Typedef struct objc_category * Category;/* the compiler generates such a structure for each Category. A class can have multiple classes, including both the instance method and the class Method */struct objc_category {const char * category_name;/* class name. define */const char * class_name;/* class name */struct objc_method_list * instance_methods;/* The instance method defined in the Link class. NULL indicates no instance method. */struct objc_method_list * class_methods;/* class methods defined in the Link class. NULL indicates no class method. */struct objc_protocol_list * protocols;/* protocol table */};
Objc_property_t
typedef struct objc_property *objc_property_t;
IMP
id (*IMP)(id, SEL, ...)
SEL
typedef struct objc_selector *SEL; struct objc_selector{ void *sel_id; const char *sel_types;};
Objc_method_list
Struct objc_method_list {struct objc_method_list * method_next;/* this variable is used to link another independent method linked list */int method_count; /* Number of methods defined in the Structure */struct objc_method method_list [1];/* variable length structure */};
Objc_cache
struct objc_cache{ unsigned int mask; unsigned int occupied; Method buckets[1];};
Objc_protocol_list
struct objc_protocol_list{ struct objc_protocol_list *next; size_t count; struct objc_protocol *list[1];};
Data Structure id of the Instance
typedef struct objc_object *id;
Objc_object
Struct objc_object {/* Class pointer is an object-related Class. If it is a Class object, this pointer points to the Meta Class. Class isa ;};
Objc_super
Struct objc_super {id self;/* receiver of the Message */Class super_class;/* parent Class of the receiver */};
Previous