Before we can really delve into the inner workings of the Molecule Engine’s memory system, we need to cover some base ground first. Today, we’re taking a very thorough look at new, delete, and all their friends. There are some surprising subleties involved, and judging from the interviews I conducted, sometimes even senior level staff messes up questions regarding the inner workings of new and delete.
Tag Archives: C++
Designing extensible, modular classes
One problem which often arises during programming is building a base set of functionality which can be extended by the user, while still being modular enough to make it easy to replace only certain parts of an implementation. I guess everybody of us has faced this problem at least once, and came up with different solutions. There is a really powerful and elegant technique for solving this kind of problem, which is what I want to show today.
Type-based dispatching
Today’s useful C++ technique is type-based dispatching. This can be used whenever you want to call different functions based on properties of a certain class, without paying unnecessary performance penalties.
Hashed strings
One scenario that is quite common in all game engines is having to look-up some resource (texture, shader, material, script, etc.) based on a string, which could look like the following:
Texture* tex = TextureManager::FindTexture("my_texture");
Subtle differences in C++
Let’s start this post with a small C++ quiz. Consider the following class:
class Eater { public: template <size_t N> void Feed(const char (&str)[N]); void Feed(const char* str); };