How does the Objective-C runtime instantiate the root metaclass and other class definitions?

I am trying to implement the basic object-oriented ANSI C runtime and use Objective-C as a guide.

It seems that they are three parts. Class description, class interface and class implementation. To create an instance of a class interface, the familiar method of using a class object to instantiate a single object can only occur if the runtime has already created the class object using the class description.

So, are all the class definitions statically assigned the first time that they are created to make it possible to instantiate using the Class object? Or, if they are distributed dynamically (on the first call), how? Is this part of the execution loop or is the class actually a function that determines if it was already allocated or not before the message was redirected?

+7
c instantiation metaclass class objective-c-runtime
source share
1 answer

The runtime does some initialization through constructor functions that are called before the program actually executes. They go __attribute__((constructor)) both gcc and clang.

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

These functions use data automatically embedded by the compiler. They do things like building hash tables for the class lookup function, which are then used to actually pass messages.

Instances on the other hand are distributed dynamically.

I do something similar, so I don’t know much better than this, but it is as deep as I dug.

+5
source share

All Articles