同标准的内存分配库一样,谷歌和微软都有自己的通用分配器,微软的名为 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
附录
参考链接
本文由 柒 创作,采用 知识共享署名4.0
国际许可协议进行许可。
转载本站文章前请注明出处,文章作者保留所有权限。
最后编辑时间: 2023-08-26 22:08 PM
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!!
请教下如何在windows上使用
在其项目说明页中有提供:https://github.com/microsoft/mimalloc#windows