On 1/29/14, Uli Kusterer <witness.of.teacht...@gmx.net> wrote: > On 30 Jan 2014, at 00:16, Rui Pacheco <rui.pach...@gmail.com> wrote: >> To those of you doing Objective-C++ apps, is there a difference in terms >> of performance or memory usage? >> >> I've noticed that TextMate 2, which is done in Objective-C++, consumes >> less memory than the Chocolat editor which seems to be done exclusively in >> Cocoa. > > Give the nature of C++, it's not surprising that performance can often be > better. They generally tend to put a higher emphasis on performance than on > programmer comfort, maintainability etc. Also, C++ can do a lot of mean > tricks due to the more static nature of the language. E.g. their method > dispatch is not easy to keep binary stable across releases, so is really > badly suited for API design in dylibs or frameworks, but probably only needs > two pointer dereferences and one addition to resolve a method, while ObjC > actually has to perform the look-up at runtime, but therefore works much > better as a library API. > > I don't usually have to drop down to C++ unless: > > 1) I'm in very performance-critical code, like device drivers, video > decoders etc. > 2) I need my code to be cross-platform, because C++ is really the most > reliably available OO-language everywhere from Android to Windows to iOS. > > Unless you're in one of those situations, I wouldn't drop down to C++ just > because it "is probably faster". It helps nobody if your app crashes faster > because all that code you rewrote that you'd get for free in ObjC or C# or > the ADK is buggy. The more people use a piece of code, the more likely it is > one of them found a bug got it fixed. Tested code is always better than new, > "fast" code. > > Cheers, > -- Uli Kusterer > "The Witnesses of TeachText are everywhere..." > http://zathras.de > >
- Additionally, C++ will typically increase your compile and link times. - Binary compatibility (already mentioned) is a pain, so libraries need to be extremely careful. Additionally, use of templates often leads to lots more symbols and larger binary size (dynamic libraries can't really be stripped for unused symbols). - Often when comparing Obj-C vs. C++, method dispatch is one of the main culprits for the performance difference. But don't forget, Obj-C is a pure superset of C and you can always use good old C to get the same performance benefits if you don't need/want the Obj-C features. Other really high performance situations deal with cache and memory layout and it turns out that much of the C++ standard library is not well suited for dealing with this and going back to POD types and essentially C (if not assembly) is often better for performance. -Eric -- Beginning iPhone Games Development http://playcontrol.net/iphonegamebook/ _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com