如何使用微软通用分配器 mi-malloc
后知后觉 现有 3 评论

同标准的内存分配库一样,谷歌和微软都有自己的通用分配器,微软的名为 mi-malloc。是一种性能卓越的通用分配器。最初由 Daan Leijen 开发,用于 Koka 和 Lean 语言的运行时系统。

配置

在 Alpine 3.18 上构建,推荐使用 Docker 进行构建。

docker container run --rm -it alpine:3.18 /bin/sh

然后执行构建

apk add --no-cache git cmake make g++
mkdir /usr/local/src
cd /usr/local/src/
git clone https://github.com/microsoft/mimalloc.git
cd mimalloc
mkdir -p out/release
cd out/release
cmake ../..
make

安装构建产物

/usr/local/src/mimalloc/out/release # make install
[ 40%] Built target mimalloc
[ 80%] Built target mimalloc-static
[ 82%] Built target mimalloc-obj
[ 85%] Built target mimalloc-obj-target
[ 90%] Built target mimalloc-test-api
[ 95%] Built target mimalloc-test-api-fill
[100%] Built target mimalloc-test-stress
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/local/lib/libmimalloc.so.2.1
-- Installing: /usr/local/lib/libmimalloc.so.2
-- Installing: /usr/local/lib/libmimalloc.so
-- Installing: /usr/local/lib/cmake/mimalloc-2.1/mimalloc.cmake
-- Installing: /usr/local/lib/cmake/mimalloc-2.1/mimalloc-release.cmake
-- Installing: /usr/local/lib/mimalloc-2.1/libmimalloc.a
-- Up-to-date: /usr/local/lib/cmake/mimalloc-2.1/mimalloc.cmake
-- Up-to-date: /usr/local/lib/cmake/mimalloc-2.1/mimalloc-release.cmake
-- Installing: /usr/local/include/mimalloc-2.1/mimalloc.h
-- Installing: /usr/local/include/mimalloc-2.1/mimalloc-override.h
-- Installing: /usr/local/include/mimalloc-2.1/mimalloc-new-delete.h
-- Installing: /usr/local/lib/cmake/mimalloc-2.1/mimalloc-config.cmake
-- Installing: /usr/local/lib/cmake/mimalloc-2.1/mimalloc-config-version.cmake
-- Installing: /usr/local/lib/mimalloc-2.1/mimalloc.o
-- Installing: /usr/local/lib/pkgconfig/mimalloc.pc

使用

构建完成后可以将其使用在项目编译中,增加参数 -lmimalloc 即可

gcc -o hello -lmimalloc hello.c

附录

参考链接

本文撰写于一年前,如出现图片失效或有任何问题,请在下方留言。博主看到后将及时修正,谢谢!
禁用 / 当前已拒绝评论,仅可查看「历史评论」。
  1. avatarImg xnxx2 pro

    Hello, i fesel thjat i ssaw yoou visited my blo so i gott here tto return thee desire?.I aam
    trying too tto finmd thinvs too enhancee mmy website!I assume itss good enogh to make use oof a ffew oof yolur ideas!!

    Chrome 114.0 Windows 10
    IP 属地 未知
  2. avatarImg sarah

    请教下如何在windows上使用

    Chrome 117.0 Windows 10
    IP 属地 未知
    1. avatarImg
      @sarah

      在其项目说明页中有提供:https://github.com/microsoft/mimalloc#windows

      Firefox 118.0 macOS Catalina
      IP 属地 未知