Resource Management and Game Engines
I worked with C++ professionally for more than four years and I think that the memory management issues are most often found in C++ projects. There is no way in hell that you’ll not look for memory leaks and after that fix them, or look for buffer overrun bugs, or resolve a weird bug by finding a buffer overrun bug, or fix some other memory corruption bugs when writing C++. This is actually a big part of the C++ programmers time.
I watched some time ago a presentation by James Gosling and one of the things he said was that he created Java because he spent so much time debugging memory bugs that he wanted to make sure he will not do that again. I programmed in Java, maybe more than I programmed in C++ and for a moment I really felt that. In that moment I remembered how it is to write code and not think about freeing things and not think about who destroys who, and what to delete in your destructor and all that: it’s so much fun. Sure it’s fun when I want control and I get that and I do a really good trick to save memory but most of the time I don’t care about memory. Most of that code seems so repetitive. So boring!
But the problem remains. It needs to be done when writing C++ and I think about ways to do this well a lot. Recently something obvious occurred to me. In all these years I programmed in C++ doing games and in games there is not a single framework for doing things. Everybody has his own engine or framework and it occurred to me that nobody uses this to their advantage. I mean if I write a framework then I can provide some useful stuff to the end-user but at the same time I get to impose some rules on that user. I get to say how my engine is used and if I get to say that, then maybe there is a way to simplify the memory management, at least in the context of my engine. And there is! Apple does this already in Objective-C with Cocoa. I don’t understand why these things are not more common. Because of the nature of game engines I would expect to see this kind of memory management in every engine. It’s like a kind of bait: if you want to use this wonderful engine then abide by these rules and voilĂ your management for the memory is so much simple.
And also in a game engine you could have a lot of fun stuff especially for games. For example tagged allocations. I mean if I allocate everything with the tag “Level1″ attached, then when I want to free Level1 I can just say something like ResMgr->Free(“Level1″) and not care about all the things I’ve created for “Level1″ because my resource manager knows that. What I mean is that it’s not helping anyone if the code in a game engine is generic. It should be specific, it should take into account the domain.
No trackbacks yet.