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.

Strategies

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.

Bump allocator

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

First-fit allocator

Best-fit allocator

Recycler