当前位置:网站首页>The bottom implementation of block
The bottom implementation of block
2022-07-18 16:32:00 【InfoQ】
Block The underlying implementation of
- The original document :
int main(int argc, const char * argv[]) {
^{ };
return 0;
}
- adopt clang The order will OC To C++ Code to check Block Underlying implementation ,clang The command is used by the terminal cd Locate the main.m File folder , And then use it clang -rewrite-objc main.m take OC To C++, After success main.m A... Will be generated in the same directory main.cpp file
struct __block_impl {
void *isa; //isa, A pointer to the class to which it belongs , That is to say block The type of
int Flags; //flags, Flag variable , In the realization of block You'll use
int Reserved; //Reserved, Keep variables
void *FuncPtr; //block Pointer to the function called at execution time
};
struct __main_block_impl_0 {
struct __block_impl impl;
struct __main_block_desc_0* Desc;
__main_block_impl_0(void *fp, struct __main_block_desc_0 *desc, int flags=0) {
impl.isa = &_NSConcreteStackBlock; //__main_block_impl_0 Of isa The pointer points to _NSConcreteStackBlock
impl.Flags = flags;
impl.FuncPtr = fp; // from main Function , __main_block_impl_0 Of FuncPtr Points to the function __main_block_func_0
Desc = desc; //__main_block_impl_0 Of Desc It also points to the definition __main_block_desc_0 It was created when __main_block_desc_0_DATA, Which records block Structure size and other information .
}
};
static void __main_block_func_0(struct __main_block_impl_0 *__cself) {
}
static struct __main_block_desc_0 {
size_t reserved; // Keep field
size_t Block_size; //block size (sizeof(struct __main_block_impl_0))
} __main_block_desc_0_DATA = { 0, sizeof(struct __main_block_impl_0)};
// The above code defines __main_block_desc_0 When the structure is , At the same time, I created __main_block_desc_0_DATA, And assign it a value , For main Pair of functions __main_block_impl_0 To initialize .
int main(int argc, const char * argv[]) {
((void (*)())&__main_block_impl_0((void *)__main_block_func_0, &__main_block_desc_0_DATA));
return 0;
}
__block_implStructure , It containsisaThe pointer ( contain isa All pointers are objects ), in other wordsblockIt's also an object
__main_block_impl_0Structure , It can be seen that it is based on the function (main function ) And the occurrence sequence ( The first 0 individual ) Named , If it's globalblcok, It is named according to the variable name and occurrence sequence
__main_block_impl_0Contains two member variables and a constructor , The member variables are__block_implStructure and description informationDesc, Then initialize... In the constructorblockType information, function pointer and other information
__main_block_func_0function , In fact, it corresponds toblockFunction body , This function accepts a__cselfParameters , In fact, it's the correspondingblockIn itself
__main_block_desc_0Structure , The more valuable information isblockSize
mainFunction pairblockThe creation of , You can see executionblockIs to call a toblockA function that is itself a parameter , This function corresponds toblockThe executive body of
边栏推荐
- Tutorial on the principle and application of database system (021) -- database operation of MySQL
- 脱敏项目的苦乐得失
- [vsctf2022]web topic recurrence
- Debugging of diagnostic function of analog power amplifier 75610
- Meshlab 最远点采样(FPS)
- C# 串口与TCP客户端 STTech.BytesIO
- Upgrade mysql5.5.27 to 5.7.35 under Windows Environment
- 【今天的小go同学要去丢垃圾(1)】
- 索引的原理与设计原则
- 剑指 Offer 10- I. 斐波那契数列(4种解法)
猜你喜欢
随机推荐
Use flutter to make a beating heart
【生物信息】蛋白质交互课题思路成长营(14天)
行政处罚法 例外规定
查找——二叉排序树(二)
Advanced Mathematics -- Chapter 8 partial derivatives and total derivatives of implicit functions
[vsctf2022]web topic recurrence
Meshlab 最远点采样(FPS)
5 data packets and LSA information of OSPF
(cf)Codeforces Round #807 (Div. 2)A--C思维题
Sword finger offer 10- I. Fibonacci sequence (4 solutions)
安装无线网卡驱动
[initial C language] / * detailed explanation of the simulation of character functions and string functions*/
AP统计学
AP statistics
LeetCode腾讯精选练习50题-059.螺旋矩阵II
Summary: Prometheus matching pattern
【TensorFlow2.9】泰坦尼克号生存预测—结构化数据建模流程
MATLAB数字图像处理 实验二:单像素空域图像增强
工业级知识图谱de构建与应用(二):商品知识的表示和建模
INSET: Sentence Infilling with INter-SEntential Transformer









