Why do big projects like Unreal Engine write their own container classes?
Asked Answered
F

2

19

I've gone through the Unreal Engine source code and I found that they use their own container classes, for example an in-house dynamic array. But the C++ STL provides (almost) all the necessary container classes that will be required. So why do they spend time developing the same containers again? Wouldn't it be easier for the developers to use containers such as std::vector to write their code rather than trying to figure out how to do things using the TArray class in the engine?

Feldt answered 1/10, 2020 at 15:0 Comment(6)
History, perhaps? Development on the engine began in 1995, whereas the first public implementation of the STL had only been released in 1994. Sweeney may not have thought it mature enough at the time, and even if the developers changed their mind later, there may not have been good reason to go to the trouble of converting all the existing code.Kweiyang
Unreal uses it's own Reflection and GC.Hamiltonian
@NateEldredge There was a pretty long time period when STL containers were really bad performance wise. There is an interview with John Carmack where he stated that during the days of Doom 3 development (~2002-2004) STL basicly wasn't even an option for bleeding edge game development. They also rolled out their own library for these things.Sos
As someone working on my own large project, I can speak from my experience that sometimes, you find yourself requiring features tailored to your project that the C++ STL doesn't provide. One such feature in my project would be the ability to express an element as a pointer to an object of the Project's base class type if possible (which the std::vector could not offer). Also, I find myself wanting simply to rely on the Standard Library as little as possible for this project.Sharpsighted
@TrecApps Not entirely off-topic, so may I ask why? For a new project, the reasons given in the answers below don't really apply. I suggest using the STL as far as possible, and only writing your own stuff if absolutely necessary.Checkbook
This is a a good question. Maybe somebody also care to clarify why the engine is not upgraded to STL after so many years ? Perhaps the reason was not lack of STL ?Azeria
C
10

There are several reasons why a project might not use STL containers:

  1. The containers used in the project are tailor-made to have certain performance characteristics that are different from the STL versions.

  2. The STL containers might not even have existed when the custom containers were designed, and it's not worth the effort to make such a large change to a working project.

  3. While most developers are used to STL containers, most contributors to a particular project might actually be more used to the custom versions, and how they should be used, and retraining all of them might not be worth the effort either.

For any particular project, some, or all of the above, and even other reasons might contribute to the decision to use custom containers.

Checkbook answered 1/10, 2020 at 15:10 Comment(2)
Let me add that the performance characteristics of STL containers will vary across compilers and platforms, whereas writing your own library will result in a more consistent cross-platform behavior.Auteur
Also, STL containers are required to have some amount of thread safety by the standard (see this answer), which the user of the custom container might not need.Geotectonic
M
5

In addition to the reasons mentioned by @cigien - even if the developers of such applications don't need a tailor-made container, it's still the case that several standard-library containers are simply quite slow, e.g.:

Microcyte answered 1/10, 2020 at 15:25 Comment(1)
I once saw std::basic_string<int> to be used as vector with SSOAdlai

© 2022 - 2024 — McMap. All rights reserved.