Bill Bumgarner is a former Apple engineer who writes about Objective-C internals, memory debugging, and runtime behavior.
HN commenters repeatedly link his objc_msgSend series as a thorough explanation of how Objective-C messaging works, and list his blog among good Cocoa resources.
Practical example: objc_msgSend (which is called for every message send in an Obj-C program) is written in assembly so it can jump to the target method implementation without disturbing any caller-save/callee-save register state: http://www.friday.com/bbum/2009/12/18/objc_msgsend-part-1-the-road-map (and also presumably because C won't guarantee that a tail call is actually compiled as a jump).
Practical example: objc_msgSend (which is called for every message send in an Obj-C program) is written in assembly so it can jump to the target method implementation without disturbing any caller-save/callee-save register state: http://www.friday.com/bbum/2009/12/18/objc_msgsend-part-1-the-road-map (and also presumably because C won't guarantee that a tail call is actually compiled as a jump).
Assembly is more relevant today than it has been in awhile, largely because Intel has gone pretty gung-ho with vector instructions that compilers mostly can't figure out how to emit on their own.
For example, say I want to convert an array of bytes into a bitmask such that every zero-valued byte is converted into a set bit. On a 64-bit system, you can do this 64-bytes at a time:
unsigned long bits = 0;
for(unsigned char i = 0; i < 64; ++i) {
bits |= ((unsigned long)(bytes[i] == 0) << i);
}
This isn't a particularly efficient use of the CPU. If you've got a CPU that supports AVX2, you've got two very powerful instructions available to you: VPCMPEQB and VPMOVMSKB.…
Maybe not "daily", but very frequently: here is a small selection of some of the small sites on my newsblur newsfeed list: [0]
http://www.jamesaltucher.com : Much self-pity, but also sometimes quite funny.
http://www.astrobio.net/latestnews_rss/news.xml : Is there life on other planets?
http://kaygun.tumblr.com/
http://www.friday.com/bbum : Coding, hardware projects, generally interesting.
http://bestyoucanbe.blogspot.com/ : Insights into the education system in regard to the raising of his neurologically non-typical son.
http://blog.lmorchard.com
http://ex-muslim.org.uk : Oppression of atheists in the Muslim world.
http://clojurefun.wordpress.com : Clojure!
http://scientopia.org/blogs/goodmath : Bad science, denialism.
http://blog.willbenton.com : Music, logic, programming, etc.
http://www.groklaw.net : Maybe not "small"; detailed analysis of important legal cases.
http://hicksdesign.co.uk/journal : Web design.
http://www.holovaty.com/ : "I'm co-creator and co-Benevolent Dictator For Life of the open-source Django Web framework"
http://prometheus.med.utah.edu/~bwjones : Combines talented photography, photoessays, and study of the retina.
http://lee-phillips.org : I regularly check my site to see if it's still working.
http://chronicle.com/blogs/linguafranca : Language issues; can be amusing or stupid.
http://freethoughtblogs.com/maryamnamazie : Freedom for women in the Muslim world.
http://math-blog.com : Infrequently updated, but often…
Yes, but if you message the subclass with the alias, only the superclass's method gets invoked, because the alias apparently contains the IMP of the superclass's method. Or it must, if what you said before is to be believed.
This is pretty nasty, because it breaks the idea of message sends and subclass overrides of methods. There's two ways you could solve it:
1. Set the IMP to a static function that looks up the method it should forward to and re-send the message there. This is hard to do in a manner that supports all arguments, and you'd need at least 2, possibly 3 versions anyway (one for regular, one for strret, and on some architectures, one for fpret). It would probably need to be written in assembly in order to forward the arguments.
2. More recently (in iOS 4.3, and whatever the corresponding OS X release was), the runtime got a nice little function called imp_implementationWithBlock(). This takes a block and returns an IMP. Bill Bumgarner has a nice blog post about it (http://www.friday.com/bbum/2011/03/17/ios-4-3-imp_implementationwithblock/). You could use this function on every alias in order to invoke the correct method, passing along the correct arguments.
According to the link you posted, that's over four times slower than C++ virtual method dispatch (and note that most method calls in ordinary C++ code are not virtual). Also, IMP caching is hardly easy and is quite fiddly: see for example the benchmark code in that link as well as [1].
I highly recommend reading the tour of objc_msgSend [2]. It's very eye opening: for example, there's a cache scanning loop even in the fast case.
[1]: http://www.mulle-kybernetik.com/artikel/Optimization/opti-3-imp-deluxe.html
[2]: http://www.friday.com/bbum/2009/12/18/objc_msgsend-part-1-the-road-map/
Here are a couple of Stack Overflow answers that illustrate how you do it in Objective-C:
http://stackoverflow.com/a/2573949
http://stackoverflow.com/a/18689338
If you're interested in the nitty-gritty of how objc_msgSend works, bbum from Apple wrote up a great low-level walkthrough a few years back: http://www.friday.com/bbum/2009/12/18/objc_msgsend-part-1-the-road-map/
Awesome, I wasn't aware of that one.
Other good ones I know of are the already mentioned Cocoa with Love
http://cocoawithlove.com/
Cocoa is my girlfriend
http://www.cimgf.com/
and bbum's weblog-o-matic
http://www.friday.com/bbum/