7 ms·
You can actually go one step further with your "Reason 2". Many may not realize this, but everything that you can do with the "bracket" part of Objective-C you
by jballanc 15y ago
You can actually go one step further with your "Reason 2". Many may not realize this, but everything that you can do with the "bracket" part of Objective-C you can also do with straight-up C and the Objective-C Runtime methods.
This is where I get to promote my favorite page of documentation ever: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html http://developer.apple.com/library/mac/#documentation/Cocoa/...
- weaksauce 15y agoThat's an excellent page, thanks! This actually makes me wonder... how much overhead is in each objective c object over a similar struct in c?
- kstenerud 15y agoIn terms of size, they're almost the same (Objective-C classes are implemented with structs). In terms of speed, the difference is absolutely huge. You can generate a random number faster than you can make an Objective-C call. But, it's fast enough for 95% of things people do with it.
- infinite8s 15y agoExactly. Many of the benefits of Obj C's dynamism come into play with the UI, where the main speed constraint is the response time of the user. And whenever you need to write compute bound code it is easy to drop down into C.
- madmoose 15y agoObjective-C message sends are not much slower than C++ virtual calls: http://mikeash.com/pyblog/performance-comparisons-of-common-operations-iphone-edition.html http://mikeash.com/pyblog/performance-comparisons-of-common-... And that's from 2008. Clang's improved it a lot.
- Groxx 15y agoActually, that's on an iPhone. Here's the article for OSX from the start of 2008 (two months before your link), where the cached message call comes out faster than the virtual calls, and the non-cached is ~ 4.5x slower instead of ~ 2x on the iPhone: http://mikeash.com/pyblog/performance-comparisons-of-common-operations-leopard-edition.html http://mikeash.com/pyblog/performance-comparisons-of-common-...