开发者

How are method names stored in run-time memory?

开发者 https://www.devze.com 2023-03-14 17:22 出处:网络
Out of interest, how are method names stored in memory in compiled Objective-C? The main reason of interest is understanding dynamic 开发者_如何学Ctyping better.

Out of interest, how are method names stored in memory in compiled Objective-C? The main reason of interest is understanding dynamic 开发者_如何学Ctyping better.

Thanks in advance!


The source for the runtime is available, btw, if you really want to go deep.

In short; method names -- their selectors -- are stored as C strings in the mach-o of the binary. I.e. if you have a method -(void)foo:(int)a bar:(int)b;, there will be a selector foo:bar: string in the mach-o.

Type encoding information is also stored in a different segment of the mach-o file. That type information -- for which there is API in the runtime to retrieve it -- describes the type of the return value and arguments to the method.

Note that the type information is incomplete. Note also that using the type information to figure out how to generically encode/decode the arguments to and return value from a method is a downright pain.

0

精彩评论

暂无评论...
验证码 换一张
取 消