The topic of memory allocation comes up regularly in Game Development and OSDev. The choice of memory allocator can have a large impact on the performance and memory usage of a system.
Most likely, you will only use these if you are programming in systems programming languages like C, C++ or Rust.
Even if everyone re-invents the wheel, some common patterns will start to emerge. Most of these are obvious strategies that you could come up with on your own.
A bump allocator is perhaps the simplest memory allocation strategy you can code. While it is possible to deallocate memory in specific conditions using a bump alloctor, in practice this is rarely done.
Most uses of the bump allocator simply either never free the memory, or free it all at once. Due to this, there are use cases that work perfectly for this allocator.
- [GameDev] Allocating objects that live until the end of the frame, and get deallocated at once before switching to the new frame
- OSDev Allocating kernel memory that you intend to keep until shutdown
This is a very greedy algorithm.
This allocation strategy has a list of memory blocks. When an allocation is requested, the list is lineraly scanned and the first block that can fit the size is allocated and returned.