Hasty Briefsbeta

Bilingual

MicroAlloc

a day ago
  • The author created a custom memory allocator (MicroAlloc) inspired by studying the esp-idf heap allocator.
  • General-purpose heap allocators involve trade-offs between speed, overhead, and fragmentation.
  • The implementation uses a first-fit free list allocator with a metadata structure that stores offsets instead of full pointers to minimize overhead (2 bytes per allocation).
  • Embedded engineers should generally avoid dynamic allocation; static allocation, scratch buffers, block allocators, and arena allocators are safer alternatives.
  • Free() implementation includes merging adjacent free blocks, but merging can be deferred via a compile-time flag for better performance.