Not so modern c++ – Alex Dixon

submited by
Style Pass
2024-12-29 12:00:35

There have been a lot of changes and additions to the c++ standard since I started using c++ in the early 2000’s, the language itself has started to look quite different. Yet I am still using a very stripped down subset of c++ actually more c-style and only reaching for c++ and modern c++ with careful consideration. Why is this? Because I have never really coveted new language features, I have always been more focused on the ‘details’ like the maths behind graphics effects or physics mechanics and not so much about the ‘glue’ of how it all fits together. I worked on and shipped games pre c++11 and saw effective techniques that worked well and stuck with them, these techniques provide good performance even in debug builds.

For a while I was quite anti-c++, this was from optimising CPU code that was heavily object orientated and very bad in terms of L1/L2 cache miss rate. This lead me to data oriented design and to a rejection of object orientated programming for which c++ took the brunt of it. But just because c++ is an object oriented programming language doesn’t mean you have to use classes and objects. In 2014 I started working on a new game engine using c++ but writing c-style code with a c++ complier and only using some select c++ features. My main goal was to make all of my code as small, simple and fast as possible… but still with flexibility and extendability.

People may be encouraged to use std::array instead of plain c arrays or dynamic memory, honestly I have never typed the words std::array until just now. I have seen insane uses of std::vector to store and process image data. In debug stl is slower than using c arrays and while in release stl containers may work out to be zero cost abstractions I still don’t like the extra bloat in debug builds, especially in hot code that is processing large sets of data. Having a fast or at least a usable debug build is a great strength and I have seen many times over heavily stl dependent code bases can be extremely slow in debug. I am still using raw mallocs and c arrays in loads of places, years ago I wouldn’t touch stl at all, now I use it sparingly in places it works for me.

Leave a Comment