malloc / mimalloc (Microsoft research)

mimalloc is a general purpose allocator with excellent performance characteristics.- Github / [HN]

  • free list sharding: the big idea: instead of one big free list (per size class) we have many smaller lists per memory “page” which both reduces fragmentation and increases locality – things that are allocated close in time get allocated close in memory. (A memory “page” in mimalloc contains blocks of one size class and is usually 64KiB on a 64-bit system).
  • first-class heaps: efficiently create and use multiple heaps to allocate across different regions. A heap can be destroyed at once instead of deallocating each object separately.
  • bounded: it does not suffer from blowup [1], has bounded worst-case allocation times (wcat), bounded space overhead (~0.2% meta-data, with at most 16.7% waste in allocation sizes), and has no internal points of contention using only atomic operations.
  • fast: In our benchmarks (see below), mimalloc always outperforms all other leading allocators (jemalloc, tcmalloc, Hoard, etc), and usually uses less memory (up to 25% more in the worst case). A nice property is that it does consistently well over a wide range of benchmarks.

see also

  • thi.ng/tinyalloc - Tiny replacement for malloc / free in unmanaged, linear memory situations, e.g. WASM and embedded devices.
Written on June 22, 2019, Last update on March 25, 2023
memory allocator c++ malloc