9

When it comes to mobile game development on iOS and Android NDK, some developers write their own C++ containers, while others claim that STL is more than adequate for mobile game development (For example, the author of iPhone 3D Programming uses STL rather than Objective-C in his examples. His defense is that STL is no slower than Objective-C).

Then there are also mobile developers who abandon C++ entirely and develop games entirely (or mostly) in the C language (C89/C90).

What are the benefits and drawbacks of each approach?

Tetrad
  • 30,124
  • 12
  • 94
  • 143
mx2
  • 119
  • 4
  • 4
    The main criticisms against the STL are it's unpredictable memory allocation patterns and compiler support - both problems can be solved by using a STL alternative, for example EASTL or STLPort. – Raphael R. Sep 28 '11 at 13:51
  • 1
    Several answers from this question: http://gamedev.stackexchange.com/questions/268/stl-for-games-yea-or-nay touch on mobile platforms and should give you your answer. – Tetrad Sep 28 '11 at 14:35
  • 5
    I suspect for many of the people "abandoning" (more like, not ever using) C++ on mobile platforms it's less about STL and more about the awkwardness of Objective-C++ (and C++ support lagging generally on Apple's toolchain). –  Sep 28 '11 at 16:42
  • The real question is, can you write better? You're better off understanding the STL; and in the cases where it doesn't do what you want, implementing the behaviour you so require. – hiddensunset4 Jun 15 '12 at 09:15

1 Answers1

6

Let me tell you one thing first. C++ is faster than Objective-C calls. Objective-C uses message passing systems so it will have some runtime overhead when compared to C++. Just have a look at some of the comparisons here.

Coming to iOS general "app" development, it makes sense to use Objective-C built-in functions as performance cannot be a much criteria to some extent. But in game development, we need to consider these results.

When I was working on my previous project (Robokill), we optimized most of the code where ever necessary with plain-C calls (we converted our Objective-C particles class to a C++ class). Or you can even use Objective-C runtime functions for direct C calls.

Coming to your question, here's my answer: yes, STL is well optimized for its purpose. Even though the implementation code is not much readable, it's interesting to check the implementation once.

However, we can optimize Objecive-C code to some extent, by pre-caching the function pointers and making calls with the Objective-C runtime.

Hope this helps!

Laurent Couvidou
  • 9,171
  • 2
  • 41
  • 57
Ayyappa
  • 870
  • 5
  • 13