Friday, February 25, 2011

They seemed small and inoffensive, but they were bad as hell! Hence their name… Evil Minions!

What's up dudes? As promised, this time around I will talk about the rest of the implementation details for my Memory System. I already mentioned most of the internal elements of the system: the heaps types, their differences and how they are all connected together. But there are a couple details I left out on purpose in order to explain them today. So, here you have them:

The first one involves the way the user interacts with the system. The idea behind this system is to have control over memory allocations in order to improve performance and detect/correct leaks if they exist, but at the same time I want the user to feel as comfortable as possible using it. Therefore, in order to make the system feel natural to the user I overloaded the New/Delete Operators for a general general class called Object. This way, the user can still call the global new/delete operators for objects that do not inherit from this class and they will be stored in memory that is not managed by the Memory System.

On the other hand, if the user decides to create classes that inherit from this general class (Object), he will get the following benefits: data locality (he can place all similar objects inside the same heap), leak detection (in debug mode, every allocation made by the user has its file and line number stored, so they can be tracked down) and also memory control & tracking (the user can track and limit the total amount of space being used at all times).

The second (and final) important design decision taken was to make the Memory System a Singleton, and by doing this, limiting the total number of memory systems a running program can have to just ONE (1), which makes since I only want one central entity managing all heaps ever created without confusing the hell out of the user.

The Singleton Pattern, as it is called in software engineering, is done in C++ by following the next two (2) steps: (1) making the class constructors privates (thus the user cannot create different copies of this class), and (2) creating an static instance of the class which will be our one and only object ever created of this class. In my particular case the Memory System class is called "MemSys", so at the beginning and end of the program the user must call the methods "MemSys::initialize()" and "MemSys::destroy()" in order to create the system, and finally destroy it before terminating the program.

So my buddies, there you have them, all the implementation details of my programming pride, my newly born child… MemSys a.k.a. Diego Jr. There is nothing left to say regarding this one, aside from admitting that it gave me a hard fight, one that I will remember for a long time, but one from which I emerged victorious! =D

I will say goodbye for now, but I shall leave you with the following quote from this video:

 

"Welcome to the world of Gentlemen, Gentlemen". Adios!

P.S.: Stay tune for details on the file system and math library.

No comments:

Post a Comment