Memory allocation strategies


Reading time: less than 1 minute

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.

  • Game development 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

This is a very greedy algorithm.

This allocation strategy has a list of memory blocks. When an allocation is requested, the list is linearly scanned and the first block that can fit the size is allocated and returned.

Exact-fit allocator

Best-fit allocator

Recycler

Citation

If you find this work useful, please cite it as:
@article{yaltirakli,
  title   = "Memory allocation strategies",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2024",
  url     = "https://www.gkbrk.com/memory-allocation-strategies"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "Memory allocation strategies", December, 2024. [Online]. Available: https://www.gkbrk.com/memory-allocation-strategies. [Accessed Dec. 23, 2024].
APA Style
Yaltirakli, G. (2024, December 23). Memory allocation strategies. https://www.gkbrk.com/memory-allocation-strategies
Bluebook Style
Gokberk Yaltirakli, Memory allocation strategies, GKBRK.COM (Dec. 23, 2024), https://www.gkbrk.com/memory-allocation-strategies

Comments

© 2024 Gokberk Yaltirakli