Useful strategies for creating a memory manager
The following strategies are useful when creating a memory manager:
- Request large memory chunks.
- Optimize for common request sizes.
- Pool deleted memory in containers.
One of the most popular memory management strategies is to request for large memory chunks during program startup and then intermittently during code execution. Memory allocation requests for individual data structures are carved out from these chunks. This results in far fewer system calls and boosts the performance time.
In any program, certain specific request sizes are more common than others. Your memory manager will do well if it's optimized to handle these requests better.
Deleted memory during program execution should be pooled in containers. Further requests from memory should then be served from these containers. If a call fails, memory access should be delegated to any one of the large chunks allocated during program start. While memory management is primarily meant to speed up program execution and prevent memory leaks, this technique can potentially result in a lower memory footprint of the program because deleted memory is being reused. Yet another reason to write your own memory allocator!