Skip to content

mimalloc

A small, fast general-purpose memory allocator (malloc replacement) written in C.

Stars
13.5k
Forks
1.2k
Licence
MIT
Language
C
Last update
4 days ago
Type
Library

What it is

mimalloc is a memory allocator, the part of a program that hands out and reclaims memory while it runs. It can act as a drop-in replacement for the standard malloc without changing program code, for example via LD_PRELOAD on Linux or dynamic overriding on Windows. The README says it is small (about 10k lines of C), runs on many platforms, and is designed for good performance and low fragmentation.

  • Replace malloc in a C or C++ program via LD_PRELOAD on Linux or BSD systems
  • Override the default allocator on Windows using the documented dynamic override
  • Build a secure-mode allocator with guard pages and randomized allocation for hardening
  • Create and destroy separate heaps to allocate groups of objects together

Great for

  • Developers who want to try a faster or lower-memory malloc replacement in an existing C or C++ program
  • Teams running long-lived or multithreaded server software that suffers from memory fragmentation
  • Runtime or language implementers who want a compact allocator they can embed and adapt
  • Projects that need multiple heaps or first-class heap handling

Not ideal for

  • People who only need the default system allocator and have no performance or memory concerns, since the benefit may be small for them
  • Projects that need the secure build's extra protections without a performance cost, since the README cites about 10% average penalty for secure mode
  • Users who need a stable v2 or v1 line for new work; the README recommends v3 and calls v1 and v2 legacy
Step-by-step guide: how to use mimallocInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    See the README

    You'll need: A C compiler and CMake, or a prebuilt release archive for your platform

    Clone the repository

    git clone https://github.com/microsoft/mimalloc
  2. 2

    Run it

    • Download the release archive for your platform from the GitHub releases page, or clone the repository
    • Build the library following the README and documentation
    • On Linux or BSD, run your program with LD_PRELOAD pointing at libmimalloc.so as shown in the README
    • On Windows, follow the override instructions linked from the README
  3. 3

    Get the most out of it

    • Use the v3 line, which the README recommends, and check the release notes for changes
    • Read the documentation site for the full API, including first-class heaps
    • Consider the secure build option if you need hardening and can accept the cost
    • Review the README's section on getting the best performance before benchmarking

Downloads

Strengths

  • The README describes a small, consistent codebase that is easy to integrate and adapt
  • Broad platform support listed in the README, including Windows, macOS, Linux, WASM, and BSDs
  • Permissively licensed under MIT with active releases through v3.6.0

Trade-offs

  • The README's performance claims come from the authors' own benchmarks; results will vary by workload
  • Secure mode carries a performance cost the README puts around 10% on average
  • Version choice matters: the README says v3 is recommended while v1 and v2 are maintained as legacy lines

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.