Rocket and the STL

In the documentation, under “Programming / Engine Programming / Unreal Container Structures,” is a list of container structures used with Rocket.

https://rocket.unrealengine.com/docs/ue4/INT/Engine/Programming/Core/ContainerStructures/index.html

A few general questions:

  • What is the reason for using these custom container structures instead of the Standard Template Library?
  • Are there particular advantages we should know about?
  • Can / should the STL containers be used within a C++ based Rocket project? If not, why not?
1 Like

It’s a good and controversial question. Unreal has always worked this way so there are historical reasons in play, but our programmers feel that it is still the right decision today.

Some of the reasons for this, off the top of my head:

  • Fast and efficient implementation. We care deeply about every detail here.
  • Consistency across platforms (easier debugging, reliable behavior, memory layout)
  • Integration with engine features like automatic serialization, undo, copy/paste, etc.
  • STL itself has bugs and platform inconsistencies. This has only partly improved over the years. (see STLport)
  • Our containers are more lightweight and simple than STL, in general (compile times, etc.)

STL has become more bloated with time, though it’s easy to argue for new features that are sometimes useful that Unreal might not have built in. Though it’s hard to think of any really good ones, right?

There are some incidental benefits that could be argued. For example. our version of shared pointer has optional support for thread safety, because it yields much faster performance in the common case where you don’t need it.

Also we’re trying to make the containers and types a little more intuitive to programmers familiar with modern language designs. STL has been around a long time and also has a ton of baggage. I think that our container classes and core types are better suited to evolve with the times.

You should be able to use STL in your own code if you want. Let me know if it doesn’t work! Obviously, if you start using std::vector or std::shared_ptr, you are going to have to do some marshaling when you need to talk to Unreal containers. We’re always interested in hearing feedback about this stuff though.

–Mike

Thanks for the detailed answer, Mike.

I tend to lean toward the STL since it’s part of the language, and most roll-your-own implementations lack the algorithms supplied with it and the ability to match different algorithms with different containers, which is a big part of the usefulness of the implementation. Also, we shipped all 3 Metroid Prime games with it at Retro Studios with no problems and no changes (except having to roll our own vector class to avoid the automatic doubling on resize).

Still, though, if there’s nothing stopping us from using the STL where appropriate, I’m fine with it. We can pick and choose where to use it vs the container classes in Rocket.