Hasty Briefsbeta

Bilingual

Allocators Are Monkeys with Typewriters

a year ago
  • #programming
  • #buddy-system
  • #memory-allocator
  • The author explores writing a custom memory allocator to manage a preallocated region, inspired by a feature request for mimalloc.
  • Memory allocators manage allocation, deallocation, and reallocation of memory, providing interfaces similar to malloc/free/resize.
  • Memory fragmentation (internal and external) is a key problem allocators address by strategies like size-based buckets.
  • The buddy allocation system is highlighted as a simple, reliable technique, used even by the Linux kernel.
  • The buddy system works by recursively splitting memory into power-of-two chunks until the requested size is met.
  • Deallocation involves marking chunks as unused and coalescing them with their buddies if also free.
  • The author notes the simplicity of allocators, with general-purpose ones like mimalloc being only a few thousand lines of code.
  • Future plans include implementing preallocated memory usage for mimalloc.