2015-08-16 03:32:36 Posted by RetroZelda

C++ Memory Management

So, with my lack of time with my good friend, C++, I have decided to make a Memory Manager. I was playing around with a different coding style, and I think I like it. It seems more of an explicit style, and I think I like programming is this way. Anyway, this manager is similar to my MIPS memory manager(found here, and it is definitely easier to read and use. The usage is simple. I have every function static, and held in a namespace. That can easily be changed depending on whatever my next project needs are, but it is still self-sufficient. You have to call RetroZeldaMM::Init() and RetroZeldaMM::Shutdown() to allocate and free the actual memory, or if on an embedded system, to start using the given heap memory. Then, to allocate simply use RetroZeldaMM::New<>() and RetroZeldaMM::Delete<>(). Yes, they are templated functions. Deal with it :) There are 3 helper Macros to help with the amount of data to allocate: KBToByte() MBToByte() GBToByte() And then there is a function called RetroZeldaMM::AllocationCount(). You can call it to get the allocation/deallocation count as a primitive way to check if you are not releasing your pointers. Please note that the data alignment is kept on a 4byte boundary. I am not sure of I did it correctly, or if there is a keyword I need to use. Regardless, enjoy! Ciao fur Niao!