Skip to content

Instantly share code, notes, and snippets.

@yuanshanxiaoni
Created August 8, 2014 08:14
Show Gist options
  • Select an option

  • Save yuanshanxiaoni/02e261aedeafb6321b2e to your computer and use it in GitHub Desktop.

Select an option

Save yuanshanxiaoni/02e261aedeafb6321b2e to your computer and use it in GitHub Desktop.
objc runtime bootstrap
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.
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.
[https://stackoverflow.com/questions/2219501/how-does-the-objective-c-runtime-instantiate-the-root-metaclass-and-other-class]
@yuanshanxiaoni
Copy link
Author

Of course, that is done for convenience, but if you had your class descriptions stored in data files you could build the structures you need from a file. The difference is that the compiled Objc generates structures that are readily usable by the runtime, so you would be doing that part of the work JIT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment