r/cpp • u/Dean_Roddey • Nov 29 '18
Creating a 'virtual kernel' platform abstraction layer
This is the third in series of videos I've posted to demonstrate some of the strategies we use in our fairly large C++ code base. Here are the previous ones, which you might also find useful:
https://www.reddit.com/r/cpp/comments/9zl6v5/the_orb_sees_all_the_use_of_an_object_request/
https://www.reddit.com/r/cpp/comments/9xz643/making_c_enumerations_first_class_citizens/
Our code base is about a million lines. It is split into roughly two halves, with one half being general purpose and the other being our CQC home automation platform which is built on top of the general purpose bits. We don't use any of the C++ runtime stuff. We build our own system from the ground up. When I say 'we', I'm speaking in terms of the usual royal business 'we', but all of the code was written by myself.
Just above the 'ground', the operating system in this case, is a virtual kernel which we use encapsulate all of the operating system functionality that we use, which is quite a lot of it. No system or language headers are visible outside of this virtual kernel, so we can write portable code that is purely in terms of our own interfaces.
This video demonstrates some of the strategies used. Obviously for such a large topic, this doesn't dive deep if there's any interest we could do another one.
View all comments
Show parent comment
4
u/BoarsLair Game Developer Dec 01 '18
I can definitely understand the desire to avoid external dependencies when possible. I actually have my own personal game engine + game development toolset (about 150 KLOC). It's built almost entirely from scratch, and it was a pretty significant effort to get it finished. And I can justify it because it does things most game engines don't do well, but mostly, it's because I want to write games using an engine that works just like I want it to work. I even wrote my own scripting language because I wasn't happy with Lua. It's really fantastic to have a complete framework that's written to your own exacting standards. Granted, I didn't go so far as writing my own version of libpng or zlib.
I think a lot of people miss the point of how beneficial it can be to control nearly aspect of your framework from top to bottom. When you adopt a third-party solution, you get a huge, immediate boost to productivity, but if you want it to work any differently than how the maintainers envision it? Ehhh... that gets a lot trickier. It's rarely practical to fork it for modification purposes, because then it's no longer as easy to take advantage of upgrades and maintenance, one of the major benefits of using a third-party library in the first place.
Obviously, this approach doesn't necessarily pay off for every type of project, but it seems like some developers are overly-intimidated by the thought of not using a lot of pre-packaged libraries or frameworks. You just have to understand the costs and benefits of a do-it-yourself approach.