Public Group

# STL and game (engine) programming

This topic is 5038 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi everybody, this question has been bugging me for some time now so I figured I'd ask here. I'd like to know if STL is actually used in game engine development. I think I have a fairly good idea what STL is about, I've already read some tutorials on it and have been dabbling in it for some time now (although I'm still at the beginning with my learning). In my opinion STL's great, but I'm also aware of the fact that game engines are designed for maximum performance, and I guess the use of STL comes with some small overhead, so I wonder if the use of STL is desirable in a game engine development and if it is actually used in the development of a game engine. If those of you experienced in this field could reply, I'd really appreciate that. :) Cheers.

##### Share on other sites
This'll be one of those interesting threads...

Basically, what it boils down to is whether or not you know how to use the STL correctly. If so, you'll end up potentially saving yourself tons of development time, and won't lose (and very well may gain) performance. If you use it poorly, though, yes, you'll shoot yourself in the foot.

But I and many others here thoroughly recommend using the STL. Just know what you're doing when you use it. For example, don't use lists when you never insert or delete from the middle. Use a deque instead of a vector if you're inserting/deleting from the front. Pass your strings as const references whenever able. Etc.

Be smart, and use the STL.

##### Share on other sites
I don't see why not. From what I hear, the STL is as optimized as would be reasonably expected. I don't think the use of templates has huge impact on performance, but I could be wrong. I think the trick is simply to use the data structures appropriately.

##### Share on other sites
In my experience, most people around here who mention a policy of avoiding the STL don't really understand it. I get the feeling that there's a conception that abstraction and ease of use imply inefficiency, and on those terms the STL would look none too attractive. But the fact is that well-designed abstractions such as the STL, when used appropriately, have minimal overhead.

##### Share on other sites
Quote:
 Original post by Kelly GI don't see why not. From what I hear, the STL is as optimized as would be reasonably expected. I don't think the use of templates has huge impact on performance, but I could be wrong. I think the trick is simply to use the data structures appropriately.

Actually the mere act of using templates has ZERO performance overhead. In meta-programming use of templates even means an INCREASE in performance.
Ignorance is about the only reason not to use STL.
However, any programming construct can be misused and STL is no exception.

##### Share on other sites
Oh no, you shouldn't use the STL. I mean, it's not like they wrote containers that are easily extensible and performance friendly. It's not like they provide you with many common algorithms with which to use to manipulate the STL. Heck, it's not like it has been used by thousands of programmers and thus any bugs in the implementation would be considered well known and or fixed. Nope, don't use the STL.

brought to you by the society for better STL usage.

##### Share on other sites
Cool, thanks for your replies, folks. I know that choosing the right data structures for the job is one of the most important (and difficult) things in development of basically any application (although in case of game engines and other apps, where performance is of the essence, such bottlenecks become most apparent), and I too think that when used correctly, STL shouldn't yield any (significant) overhead, but it's always good to get advice from more experienced developers. ;) I guess I'll be grabbing Josuttis' book about STL real soon, online tutorials just don't seem to cut it for me. :)

Anyway, thanks again for the replies.

##### Share on other sites
I've also been playing around with STL since I learned about it a couple of weeks ago (I thought it HAD to be better than standard arrays!). Anyways, I really like them so far! Very easy to learn and implement...although. In this shooter I'm making I've been told I'm using my vector incorrectly. What I'm doing with it is dynamically creating aliens as they get spawned and putting them into the vector like so:

for (int i=0; i<number; i++) {
pAliens = new Alien_Object(&m_alien, Path, i);
vAliens.push_back(*pAliens);

I was told by snk_kid I don't need to use NEW as STL will handle the memory allocation. Can anyone explain to me (in a way my tiny newbie brain can undertand of course ;) how I should go about doing that? In other words how do I create new instances of an object using my STL vector?

##### Share on other sites
Quote:
 Original post by whaleyboyfor (int i=0; i

for(int i = 0; i < number; ++i) {  vAliens.push_back(Alien_Object(&m_alien, Path, i));}

##### Share on other sites
Oh lord! That's so obvious it's embarrasing! Thanks tho washu! :)

• 16
• 11
• 10
• 9
• 49
• ### Forum Statistics

• Total Topics
631392
• Total Posts
2999741
×