mimalloc (pronounced "me-malloc") is a general purpose allocator with excellent performance characteristics. Initially developed by Daan Leijen for the runtime systems of the Koka and Lean languages.
Latest release tag: v2.1.7 (2024-05-21).
Latest v1 tag: v1.8.7 (2024-05-21).
mimalloc is a drop-in replacement for malloc and can be used in other programs
without code changes, for example, on dynamically linked ELF-based systems (Linux, BSD, etc.) you can use it as:
> LD_PRELOAD=/usr/lib/libmimalloc.so myprogram
It also includes a robust way to override the default allocator in Windows. Notable aspects of the design include:
free operations, and another one for concurrent free
operations. Free-ing from another thread can now be a single CAS without needing
sophisticated coordination between threads. Since there will be
thousands of separate free lists, contention is naturally distributed over the heap,
and the chance of contending on a single location will be low -- this is quite
similar to randomized algorithms like skip lists where adding
a random oracle removes the need for a more complex algorithm.The documentation gives a full overview of the API. You can read more on the design of mimalloc in the technical report which also has detailed benchmark results.
Enjoy!
master: latest stable release (based on dev-slice).dev: development branch for mimalloc v1. Use this branch for submitting PR's.dev-slice: development branch for mimalloc v2. This branch is downstream of dev (and is essentially equal to dev except for
src/segment.c)Note: the v2.x version has a different algorithm for managing internal mimalloc pages (as slices) that tends to use reduce
memory usage
and fragmentation compared to mimalloc v1.x (especially for large workloads). Should otherwise have similar performance
(see below); please report if you observe any significant performance regression.
2024-05-21, v1.8.7, v2.1.7: Fix build issues on less common platforms. Started upstreaming patches
from the CPython integration. Upstream vcpkg patches.
2024-05-13, v1.8.6, v2.1.6: Fix build errors on various (older) platforms. Refactored aligned allocation.
2024-04-22, v1.8.4, v2.1.4: Fixes various bugs and build issues. Add MI_LIBC_MUSL cmake flag for musl builds.
Free-ing code is refactored into a separate module (free.c). Mimalloc page info is simplified with the block size
directly available (and new block_size_shift to improve aligned block free-ing).
New approach to collection of abandoned segments: When
a thread terminates the segments it owns are abandoned (containing still live objects) and these can be
reclaimed by other threads. We no longer use a list of abandoned segments but this is now done using bitmaps in arena's
which is more concurrent (and more aggressive). Abandoned memory can now also be reclaimed if a thread frees an object in
an abandoned page (which can be disabled using mi_option_abandoned_reclaim_on_free). The option mi_option_max_segment_reclaim
gives a maximum percentage of abandoned segments that can be reclaimed per try (=10%).
2023-04-24, v1.8.2, v2.1.2: Fixes build issues on freeBSD, musl, and C17 (UE 5.1.1). Reduce code size/complexity
by removing regions and segment-cache's and only use arenas with improved memory purging -- this may improve memory
usage as well for larger services. Renamed options for consistency. Improved Valgrind and ASAN checking.
2023-04-03, v1.8.1, v2.1.1: Fixes build issues on some platforms.
2023-03-29, v1.8.0, v2.1.0: Improved support dynamic overriding on Windows 11. Improved tracing precision
with asan and Valgrind, and added Windows event tracing ETW (contributed by Xinglong He). Created an OS
abstraction layer to make it easier to port and separate platform dependent code (in src/prim). Fixed C++ STL compilation on older Microsoft C++ compilers, and various small bug fixes.
2022-12-23, v1.7.9, v2.0.9: Supports building with asan and improved Valgrind support.
Support arbitrary large alignments (in particular for std::pmr pools).
Added C++ STL allocators attached to a specific heap (thanks @vmarkovtsev).
Heap walks now visit all object (including huge objects). Support Windows nano server containers (by Johannes Schindelin,@dscho).
Various small bug fixes.
2022-11-03, v1.7.7, v2.0.7: Initial support for Valgrind for leak testing and heap block overflow
detection. Initial
support for attaching heaps to a speficic memory area (only in v2). Fix realloc behavior for zero size blocks, remove restriction to integral multiple of the alignment in alloc_align, improved aligned allocation performance, reduced contention with many threads on few processors (thank you @dposluns!), vs2022 support, support pkg-config, .
2022-04-14, v1.7.6, v2.0.6: fix fallback path for aligned OS allocation on Windows, improve Windows aligned allocation
even when compiling with older SDK's, fix dynamic overriding on macOS Monterey, fix MSVC C++ dynamic overriding, fix
warnings under Clang 14, improve performance if many OS threads are created and destroyed, fix statistics for large object
allocations, using MIMALLOC_VERBOSE=1 has no maximum on the number of error messages, various small fixes.
2022-02-14, v1.7.5, v2.0.5 (alpha): fix malloc override on
Windows 11, fix compilation with musl, potentially reduced
committed memory, add bin/minject for Windows,
improved wasm support, faster aligned allocation,
various small fixes.
Special thanks to:
mimalloc.mimalloc is used in various large scale low-latency services and programs, for example:
<a href="https://www.bing.com"><img height="50" align="left" src="https://upload.wikimedia.org/wikipedia/commons/e/e9/Bing_logo.svg"></a> <a href="https://azure.microsoft.com/"><img height="50" align="left" src="https://upload.wikimedia.org/wikipedia/commons/a/a8/Microsoft_Azure_Logo.svg"></a> <a href="https://deathstrandingpc.505games.com"><img height="100" src="doc/ds-logo.png"></a> <a href="https://docs.unrealengine.com/4.26/en-US/WhatsNew/Builds/ReleaseNotes/4_25/"><img height="100" src="doc/unreal-logo.svg"></a> <a href="https://cab.spbu.ru/software/spades/"><img height="100" src="doc/spades-logo.png"></a>
Open ide/vs2022/mimalloc.sln in Visual Studio 2022 and build.
The mimalloc project builds a static library (in out/msvc-x64), while the
mimalloc-override project builds a DLL for overriding malloc
in the entire program.
We use cmake<sup>1</sup> as the build system:
> mkdir -p out/release
> cd out/release
> cmake ../..
> make
This builds the library as a shared (dynamic)
library (.so or .dylib), a static library (.a), and
as a single object file (.o).
> sudo make install (install the library and header files in /usr/local/lib and /usr/local/include)
You can build the debug version which does many internal checks and maintains detailed statistics as:
> mkdir -p out/debug
> cd out/debug
> cmake -DCMAKE_BUILD_TYPE=Debug ../..
> make
This will name the shared library as libmimalloc-debug.so.
Finally, you can build a secure version that uses guard pages, encrypted free lists, etc., as:
> mkdir -p out/secure
> cd out/secure
> cmake -DMI_SECURE=ON ../..
> make
This will name the shared library as libmimalloc-secure.so.
Use ccmake<sup>2</sup> instead of cmake
to see and customize all the available build options.
Notes:
sudo apt-get install cmakesudo apt-get install cmake-curses-guiYou can also directly build the single src/static.c file as part of your project without
needing cmake at all. Make sure to also add the mimalloc include directory to the include path.
The preferred usage is including <mimalloc.h>, linking with
the shared- or static library, and using the mi_malloc API exclusively for allocation. For example,
> gcc -o myprogram -lmimalloc myfile.c
mimalloc uses only safe OS calls (mmap and VirtualAlloc) and can co-exist
with other allocators linked to the same program.
If you use cmake, you can simply use:
find_package(mimalloc 1.4 REQUIRED)
in your CMakeLists.txt to find a locally installed mimalloc. Then use either:
target_link_libraries(myapp PUBLIC mimalloc)
to link with the shared (dynamic) library, or:
target_link_libraries(myapp PUBLIC mimalloc-static)
to link with the static library. See test\CMakeLists.txt for an example.
For best performance in C++ programs, it is also recommended to override the
global new and delete operators. For convenience, mimalloc provides
mimalloc-new-delete.h which does this for you -- just include it in a single(!) source file in your project.
In C++, mimalloc also provides the mi_stl_allocator struct which implements the std::allocator
interface.
You can pass environment variables to print verbose messages (MIMALLOC_VERBOSE=1)
and statistics (MIMALLOC_SHOW_STATS=1) (in the debug version):
> env MIMALLOC_SHOW_STATS=1 ./cfrac 175451865205073170563711388363
175451865205073170563711388363 = 374456281610909315237213 * 468551
heap stats: peak total freed unit
normal 2: 16.4 kb 17.5 mb 17.5 mb 16 b ok
normal 3: 16.3 kb 15.2 mb 15.2 mb 24 b ok
normal 4: 64 b 4.6 kb 4.6 kb 32 b ok
normal 5: 80 b 118.4 kb 118.4 kb 40 b ok
normal 6: 48 b 48 b 48 b 48 b ok
normal 17: 960 b 960 b 960 b 320 b ok
heap stats: peak total freed unit
normal: 33.9 kb 32.8 mb 32.8 mb 1 b ok
huge: 0 b 0 b 0 b 1 b ok
total: 33.9 kb 32.8 mb 32.8 mb 1 b ok
malloc requested: 32.8 mb
committed: 58.2 kb 58.2 kb 58.2 kb 1 b ok
reserved: 2.0 mb 2.0 mb 2.0 mb 1 b ok
reset: 0 b 0 b 0 b 1 b ok
segments: 1 1 1
-abandoned: 0
pages: 6 6 6
-abandoned: 0
mmaps: 3
mmap fast: 0
mmap slow: 1


职场AI,就用扣子
AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!


多风格AI绘画神器
堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。


零代码AI应用开发平台
零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。


免费创建高清无水印Sora视频
Vora是一个免费创建高清无水印Sora视频的AI工具


最适合小白的AI自动化工作流平台
无需编码,轻松生成可复用、可变现的AI自动化工作流

大模型驱动的Excel数据处理工具
基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。


AI辅助编程,代码自动修复
Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。


AI论文写作指导平台
AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。


AI一键生成PPT,就用博思AIPPT!
博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生 成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。


AI赋能电商视觉革命,一站式智能商拍平台
潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。
最新AI工具、AI资讯
独家AI资源、AI项目落地

微信扫一扫关注公众号