如何Objective-C的运行实例的根元类和其他类的描述? [英] How does the Objective-C runtime instantiate the root metaclass and other class descriptions?

查看:119
本文介绍了如何Objective-C的运行实例的根元类和其他类的描述?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个基本的面向对象的ANSI C运行库和使用Objective-C作为指导。

I'm trying to implement a basic object-oriented ANSI C runtime and using Objective-C as a guide.

他们好像是三部分组成。 A类描述,类接口和类实现。为了要实例化的类接口,如果运行时已使用类的描述已经实例化的类对象使用Class对象实例化一个人的对象熟悉的方法只能发生。

They're seems to be three parts. A Class Description, Class Interface, and Class Implementation. In order for the Class Interface to be instantiated, the familiar method of using the Class object to instantiate one's object can only happen if the runtime has already instantiated your class object using the class description.

那么,在第一次运行静态分配提供使用Class对象实例的能力,所有的类定义?或者,如果他们是动态分配(初始调用),怎么样?是它的运行循环的一部分或为类实际上是确定它是否已经被分配或一个函数来转发消息之前没有

So are all Class definitions allocated statically at first run to provide the ability to instantiate using the Class object? Or if they are allocated dynamically (on initial call), how? Is it a part of the run loop or is the Class actually a function that determines if it has already been allocated or not prior to forwarding the message?

推荐答案

运行时不通过构造函数初始化一些实际的程序执行之前被调用。他们去了 __ __属性((构造函数))在GCC和铿锵。

The runtime does some initialization via constructor functions that get called before actual program execution. They go by __attribute__((constructor)) in both gcc and clang.

在Objective-C中的情况下,他们中的一些被嵌入在由编译器二进制文件。你将不得不将其包含在你的头类似的效果。

In the case of Objective-C some of them are embedded in the binary by the compiler. You would have to include them in your headers for similar effect.

这些函数使用编译器自动嵌入的数据。他们做的事情,如建立哈希表的类查找功能然后将它们用于实际的消息传递。

These functions use data automatically embedded by the compiler. They do things such as building hash tables for the class lookup function which are then used for the actual message passing.

另一方面实例是动态分配的。

Instances on the other hand are allocated dynamically.

我做类似的东西,所以我真的不知道比这更好的了很多,但是这是我一样深沉挖。

I am doing something similar, so I don't really know a lot better than that, but this is as deep as I have dug.

这篇关于如何Objective-C的运行实例的根元类和其他类的描述?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆