Question about the use of stl in game engines.

Started by
41 comments, last by HAM 17 years, 3 months ago
STL reduces implementation time and bugs, and is implemented and checked by several very smart people. This whole debate reminds me of the "lol assembly" discussions that crop up every so often.
Quote:Original post by Telastyn
The only reasonable argument I've heard against the C++ Standard Library in games is the missing or poor implementations on certain consoles.
Even in that case, it's possible to quickly port STLport to whatever system you're working on.

Pretty much all you need to put STLport on a new platform is a semi-proper C++ compiler and a few hours of your time watching it compile. I think some of the more recent console SDKs even come with STLport included.
Advertisement
There's no problem in using the STL in games. Hell, we use the STL (CodeWarrior's standard version I belive) extensively (vector, list, map, string, and algorithms mainly) in our DS games. And the DS isn't the most powerful machine out there either...
Quote:Original post by evolutional
I remember seeing some results posted by snk_kid to compare the performance of Doom3's custom containers to the equivalent STL containers. The STL implementations won out by a huge factor.


Doom3 is not the only one. The Microsoft Black Ops perf analysis team routinely perform exactly the same comparison for all games they review. In almost all cases, the STL wins out significantly.

It is very rare that there is a need for a container that does not exist in the STL, and even rarer that a container is provided in the STL and not performant.
The reasonable beefs with the standard library, I think, come down to two major points:

1. The fact that sometimes you DO need to worry about internals. The allocator system is okay at letting you do this, but it isn't perfect. IIRC, there's a guy here from EA who developed EA's STL replacement, which gives you better customizability.

2. The fact that it wants you to do some functional programming, in a language which does not fundamentally support functional programming. Boost::bind and boost::lambda get around this funcamental limitation, but they have their own problems. This isn't a big problem for most people, though, since they basically just ignore find_if and for_each and accumulate and whatnot.

What I would stress, though, is that both of these problems should not be considered problems until you KNOW they are problems. That is, if all you're worried about is "maybe vector will waste space, and maybe that'll make my game suck", and you don't have a report generated by your profiler telling you "vector IS wasting space and it IS making your game suck", don't worry about it.
My 2 cents:

Modern compilers optimise the STL so well it's hard to tell the difference between ordinary C arrays, performance wise. Given that they're well tested, well established, and extremely useful in debug (dialog saying "iterator out of bounds" vs. trashing random memory addresses), there aren't many excuses not to use them. The time you'll save on code maintenance is huge, as well.

Oh, also specifically in VS2005, to squeeze most performance out of STL you'll want to add a release build preprocessor _SECURE_SCL=0, unless you want the "secure" features (I don't understand/care about them).
Construct (Free open-source game creator)
i use stl all the time though i admit sometimes its unintuative
eg how can i remove all items from a container (+ resize) if they equal num, i came up with this (which cant be the best method)
A.erase( remove_if( A.begin(), A.end(), bind2nd(equal_to<int>(),num ) ), A.end() );


Use STL when you see a need.

Me I'm using std::vector now because I got bored of rewriting link list each time. Now I code faster, because I don't loose time remaking all those link list.
But my code is a little bit slower, but it's the fault of "not using STL properly".
Quote:Original post by Daivuk
Use STL when you see a need.

Me I'm using std::vector now because I got bored of rewriting link list each time. Now I code faster, because I don't loose time remaking all those link list.
But my code is a little bit slower, but it's the fault of "not using STL properly".
Emphasis mine. By the way, you do realize that std::vector is a resizing array? If you want a linked list, you use std::list.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Quote:Original post by zedzeek
i use stl all the time though i admit sometimes its unintuative
eg how can i remove all items from a container (+ resize) if they equal num, i came up with this (which cant be the best method)
A.erase( remove_if( A.begin(), A.end(), bind2nd(equal_to<int>(),num ) ), A.end() );


Actually, I think this is the best method. If you're doing this often you'd just create a small function to wrap it. The compiler can inline the function, the equal_to, the call to bind2nd, the resulting binder object, etc. With a good compiler the result will probably be code that would be difficult to beat even in pure assembly and at least as good as anything that could be writen in pure C.
Thank you all for your help. That is extremely helpful.

Jeremy (grill8)

This topic is closed to new replies.

Advertisement