Hi to all,
I was a bit absent during the last 2 months, there is a reason:
I was working on a complete Memory Management System for S2Engine.
It has been a very hard work but results are very satisfying.
WHY A CUSTOM MEMORY MANAGEMENT SYSTEM?
Generally programmers don't care about how data are allocated/deallocated in the heap memory, 'cause they can use safely new/delete (C++ language) and malloc/free (C language) standard language allocator functions.
BUT in the case of a complex program such as a game engine there are problems using standard allocators:
- They are too much general purpouse, so poor optimized for our specific needs
- They are black box, so it is hard to trace memory for leaks or debugging (what happens? why crashes? why consumes so much memory?)
- They are not deterministic, so you don't know where data are placed in memory and how much memory is reserved/committed
Until now S2Engine used just new/delete for allocate/deallocate data, so I encountered all these problems during the development.
Unitl now.
It's clear, as said before, that to make things better it was crucial to completely override the memory allocation/deallocation functions, in order to:
- Trace memory leaks
- Speed-up allocations
- See what happens when something goes wrong
- Choose myself where to place data and how much reserved/committed memory must grow, for reducing memory fragmentation
S2ENGINE HD CUSTOM ALLOCATORS
The new memory management system make all this possible.
it is based, of course, on custom allocators. Every allocator is composed by different types of suballocators, basing on the data size: small data blocks are allocated/deallocated faster, large ones are fitted better in memory.
Each allocator manages a system module: one for rendering, one for physics, one for resources, etc.. and take into account how many allocations/deallocations are made, how much memory is used, how much memory is reserved by the operating system.
Each allocator can be configured basing on the data set it must manage (how many small data blocks? medium? large?)
Also I've noticed a sppedup of allocations/deallocations after replacing new/delete with my custom allocators.
The next image shows the memory profiler implemented into the s2engine editor. It shows you the reserved/committed/used bytes for each subsystem heap and the total
FUTURE
The memory system was the basic, very very very important milestone, it is the beginning of a new S2Engine HD development era.
With this new memory system there are things that could improve a lot in the next future, such as:
- Debugging and memory leaks fighting
- Speeding-up code
Currently I'm continuing to test the engine witjh the new system (also it has just helped me in discovering a couple of leaks) and making the latest bug-fixing submitted on TRELLO board, before the releasing of next update.
I think next release should be more stable and a bit faster, thanks to this new memory management strategy.
I think it should be ready in a couple of weeks.
STAY tuned!
