The system provides an interface to a low-level block memory allocator. The block memory allocator provides methods to allocate and deallocate memory of specific fixed sized blocks.
Additionally, the system can tell if an address was allocated by it. This is useful for determining if memory was indeed allocated by Mem Block and whether or not it was released. The underlying block memory allocator can continuously allocate memory as required.
It provides a method for determining memory usage providing the user with statistics regarding the number of used and free blocks. In addition to a generic fixed block memory allocator, the system provides customized int and double memory allocators for allocating fixed blocks of integers and double floating point types.
The higher level interfaces to Mem Block provide C memory allocation routines such as
free. These interfaces are built upon the low-level block allocator. They behave in a similar manner to the application code as the built-in allocators. The exception being that they are optimized.
At the highest level are the C++ interfaces to operator
new and operator
delete. These are implemented by Mem Block and provide optimized memory allocation for application code.
In order to utilize Mem Block in Object Oriented code, the user includes the special header file
mem_block_new.h within a given class declaration. That class then has
delete declared for it, and can begin using Mem Block's interface for memory allocation and deallocation.
Mem Block provides debugging functionality when compiled with memory debugging enabled. The
check_memory() function checks the fragmentation of the allocator.
Additionally, there are checks for common memory problems such as double free, where a pointer is freed more than once. The system can also check for free of NULL pointer or a free on a pointer that was not allocated by Mem Block. Furthermore, Mem Block provides an ability for checking if a write occurs outside of bounds.
Mem Block provides an ability for the allocator to be calibrated based on the size of blocks that the allocator will be providing. The system does this by allowing the user to run the allocator with debugging turned on, and a special method called
show_map() is called to generate a map of the sizes that the allocator was requested to allocate.
The sizes can then be given to the allocator on startup to allow it to configure itself for optimized memory allocation for the sizes the application code requires. The user may specify a custom map instructing the allocator on how to optimize its allocations.