STL and game (engine) programming

Started by
8 comments, last by whaleyboy 19 years, 7 months ago
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.
Advertisement
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.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
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.
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.
Quote:Original post by Kelly G
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.

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.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
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.

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

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.
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?

Quote:Original post by whaleyboy
for (int i=0; i<number; i++) {
pAliens = new Alien_Object(&m_alien, Path, i);
vAliens.push_back(*pAliens);


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

In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.

Oh lord! That's so obvious it's embarrasing! Thanks tho washu! :)

This topic is closed to new replies.

Advertisement