• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Sepiantum

STL, yay or nay?


17 posts in this topic

The use of C++'s STL has been widely disputed over time, and I'm confused as to if one should use it in a game engine or not. Post your ideas on its use and I will take them into consideration in my journey into the creation of a game engine.
0

Share this post


Link to post
Share on other sites
One thing is for sure: your [b]first [/b](and second and third) game engine won't be bottlenecked by the STL in any way. Plus, you also get to save time in order to devote more time into the actual game engine code.
0

Share this post


Link to post
Share on other sites
Rules like that need context.

Go WAY back to before C++ was standardized (almost 14 years ago) and it made tons of sense. The rule was simple: Don't use it because it didn't really exist as a standard. It was an external library that was unproven on the tiny game systems.

Later after the standard it was a bit more complex. Machines were bigger and faster. Some systems were great, but other compilers had bad support. Optimizations that are common today were not used back then. Templates were bloated because compilers would blindly duplicate code. Template expansions could be so large they broke debuggers and tools. Support on smaller compilers ranged from poor to non-existent. Not using it in console games was good advice back in 1999 to 2001 or so. On a few oddball systems the advice may still be valid.

Today those are not true. All major compilers and tools have excellent support. More programmers understand the libraries and are able to use them properly.


You always need to understand the context of rules like this. Fancy bit tricks that made sense in a world of un-pipelined CPUs with no cache are huge performance killers on heavily pipelined out-of-order processing cores. Advice that made sense for single processors doing time-sliced threading can be horrible for multi core machines we use today. Advice from years past may not apply today. You must understand the context.
2

Share this post


Link to post
Share on other sites
Yes absolutely. Learn to use it and it will treat you well, master it and it will treat you even better. Only consider rolling your own when you're certain you've used the STL containers as efficiently as they allow themselves to be (e.g. If allocation is a bottleneck, use custom allocators).

Algorithmically, the STL is pretty sound, however you may find situations where a purpose-built approach could exploit assumptions, or that the STL doesn't provide a good data structure for. Assuming boost doesn't have a good solution either, then consider implementing your own.
0

Share this post


Link to post
Share on other sites
EDIT: Just noticed Ravyne's post... he said what I was trying to say better than I did. :)

About seven years ago (2004), I used STL in one of my projects. Back then, I was still using Visual C++ 6.0.

Then I decided to look into porting that project to Linux. I figured a good "stepping stone" would be to compile it using a Windows version of GCC. I can't remember if it was MingW or Cygwin.

GCC gave all sorts of compiler errors, and they were caused by differences between how STL is implemented in different compilers.

So I decided to replace all usage of STL classes with my own custom-made classes, where I could guarantee that if it compiles in one compiler, then it'll compile in others. I figured I wouldn't have to worry about STL having "breaking changes" in "future" compilers such as Visual C++ 2005 and updates to GCC.

I found other problems with STL too. So I've been using my own custom classes since then. Because of that, I don't really know if all these problems with STL have been solved in the newest compilers like Visual C++ 2010 and the newest versions of GCC.

Now I regret not using STL recently as I've been applying for jobs and I wind up taking tests which ask STL questions. And that particular job description didn't even mention STL. I guess some people feel that if C++ is mentioned in the job description, then knowledge of STL is implied.

So if I were in your shoes, I would use STL. However, be prepared for the possibility that you may run into weird problems with STL later on. I would make your code flexible enough that you could substitute custom classes in place of STL classes later on if the need arises.
1

Share this post


Link to post
Share on other sites
When you're a hobbyist, simply use STL. It will make you more productive (you're using your time to write your game, not linked-list implementations). It's a great general purpose library.

And that's exactly why it's sometimes despised. Games are quite a niche, and especially memory management can be quite tricky. That's what gave rise to things like EASTL (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2271.html).
0

Share this post


Link to post
Share on other sites
A decade or more ago, anti-STL mentality may have made sense, but not in 2011.

C++ is probably the only language where people have been criticized for using the [b]standard[/b] library. :blink:

Luckily this is changing.
1

Share this post


Link to post
Share on other sites
[quote name='Chris_F' timestamp='1322324470' post='4887903']
C++ is probably the only language where people have been criticized for using the [b]standard[/b] library. :blink:
[/quote]
It's happened in D too. Of course D 1.0 had this weird situation where the standard standard library was judged insufficient by some members of the community so an alternate, incompatible, standard library was developed. To this day I'm still unsure how exactly the Phobos/Tango split happened. Fortunately in D 2.0 this is no longer the case.
0

Share this post


Link to post
Share on other sites
I also regret not having learned the STL sooner. There are things in the C++ standard or Boost libraries I don't use because I think they take the fun out of programming in C++ (such as the smart pointers: I prefer handling allocation and deletion myself) but collections classes are annoying to make and those of the STL are debugged, probably thread-safe, and peer-reviewed by people that know the language up to its smallest details, and I wouldn't have any fun writing them myself anyway.

My only complaint about it is purely cosmetic: its old all_in_lowerspace name styles clash uglily with the modern coding styles.
0

Share this post


Link to post
Share on other sites
[quote name='Bearhugger' timestamp='1322687763' post='4889196']
My only complaint about it is purely cosmetic: its old all_in_lowerspace name styles clash uglily with the modern coding styles.[/quote]
Amusingly enough, CamelCase dates back to the 1970's, while underscores are quite popular with 'modern' languages (Python, C++, etc.).
0

Share this post


Link to post
Share on other sites
[quote name='Bearhugger' timestamp='1322687763' post='4889196']
I also regret not having learned the STL sooner. There are things in the C++ standard or Boost libraries I don't use because I think they take the fun out of programming in C++ (such as the smart pointers: I prefer handling allocation and deletion myself) but collections classes are annoying to make and those of the STL are debugged, probably thread-safe, and peer-reviewed by people that know the language up to its smallest details, and I wouldn't have any fun writing them myself anyway.

My only complaint about it is purely cosmetic: its old all_in_lowerspace name styles clash uglily with the modern coding styles.
[/quote]

The _Capital character stuff STL uses is due to the fact that that particular format is reserved for global scoped identifiers and that is what you want your standard library to use and not much else. And seeing that STL is often implemented by the compiler coders they are implemented as first class identifiers and hence use the reserved formats.

See this [url="http://msdn.microsoft.com/en-us/library/565w213d.aspx"]link[/url] for more info.

On the current gen consoles there are still differences between STL versions and so it is better to use your own STL versions, whether they are wrappers over the platform STL or your own implementations. This allows you to provide one interface to all the code above it which makes writing code for multiple platforms far easier.

Having said that you best learn how to use STL as even the custom implementations often just follow the normal STL interface.

0

Share this post


Link to post
Share on other sites
I have, BUT.

I'd strongly advise against using STL for runtime dynamic allocations (the exception is if you can pre-size your containers at load time). Unless you understand that what's going on behind the scenes is much the same as good-old malloc/free/realloc, then you're liable to hurt performance. Where I've found it really handy is for lists of resources (such as textures - I keep my LPDIRECT3DTEXTURE9s in an std::vector) where you don't really want to specify an upper limit but you have a potentially unknown quantity and you're not going to be needing to grow or shrink the list on any kind of a regular basis.

Having said that, STL will make your job a LOT easier when you're learning things. It nicely removed much of the burden of managing container types from your own code, allowing you to concentrate more on what your program does rather than on how it does it. Later on I would recommend that you bone up on what's happening behind the scenes, because it will enhance your understanding and enable you to make some better judgement calls on how and when to do certain things.
0

Share this post


Link to post
Share on other sites
[quote name='mhagain' timestamp='1322702204' post='4889257']
I'd strongly advise against using STL for runtime dynamic allocations (the exception is if you can pre-size your containers at load time). Unless you understand that what's going on behind the scenes is much the same as good-old malloc/free/realloc, then you're liable to hurt performance.[/quote]
Except that there is no need to replace the STL containers to fix this. It just requires the use of a replacement allocator, such as the one's supplied by the [url="http://www.boost.org/doc/libs/1_47_0/libs/pool/doc/index.html"]Boost pool allocators[/url].
1

Share this post


Link to post
Share on other sites
[quote name='Bearhugger' timestamp='1322687763' post='4889196']
There are things in the C++ standard or Boost libraries I don't use because I think they take the fun out of programming in C++ (such as the smart pointers: I prefer handling allocation and deletion myself) ...
[/quote]
We obviously have different standards of "fun" =]

[quote]
... but collections classes are annoying to make and those of the STL are debugged, probably thread-safe, and peer-reviewed by people that know the language up to its smallest details, and I wouldn't have any fun writing them myself anyway.
[/quote]
The Standard C++ Library containers are not thread safe. This consideration is not part of their specification.

They probably should not be thread safe either, due to the overhead this would require when they are not shared, and due to the fact that thread safety at the level of an individual class is often too low level, instead you need to have thread safety around a logical transaction.
1

Share this post


Link to post
Share on other sites
[quote name='rip-off' timestamp='1322733341' post='4889358']
The Standard C++ Library containers are not thread safe. This consideration is not part of their specification.
[/quote]
Thread safety isn't a binary yes/no. There are degrees of thread safety. You have to consult your compiler/standard library documentation to be sure, but most implementations offer the most basic of guarantees: as long as the allocator can be used safely across threads simultaneously safely, then two instances of containers can be modified safely in their own threads. Yes, this seems like a well-duh degree of safety, but it's possible to create a container implementation that doesn't give you this guarantee, for example, by using global state.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0