The memory module is expected to run in situations where no more dynamic memory can be obtained through the usual system calls. This implies a static allocation of all required variables, immediately placing some limits on the module usage. Since all relevant variables have to be statically allocated, all sizes have to be known in advance or set to a maximum, ideally with a single #define statement. For the current implementation, this design choice has an implication on the maximum number of pointers that can simultaneously be handled by the module.
Let us review what the module should manage. There are three kinds of memory blocks to handle:
The module infrastructure must be able to remember the type associated to each memory block to perform the correct deallocation. It must also remember the size associated to each pointer, since it is needed for memory blocks in VM or mapped files for the munmap() call.
An obvious implementation choice is to statically allocate a table to contain references to all memory allocations. This table should be initialized the first time a memory allocator is called.