<p>The preferred usage is including <code><mimalloc.h></code>, linking with the shared- or static library, and using the <code>mi_malloc</code> API exclusively for allocation. For example, </p><divclass="fragment"><divclass="line">gcc -o myprogram -lmimalloc myfile.c</div>
</div><!-- fragment --><p>mimalloc uses only safe OS calls (<code>mmap</code> and <code>VirtualAlloc</code>) and can co-exist with other allocators linked to the same program. If you use <code>cmake</code>, you can simply use: </p><divclass="fragment"><divclass="line">find_package(mimalloc 1.0 REQUIRED)</div>
</div><!-- fragment --><p> in your <code>CMakeLists.txt</code> to find a locally installed mimalloc. Then use either: </p><divclass="fragment"><divclass="line">target_link_libraries(myapp PUBLIC mimalloc)</div>
</div><!-- fragment --><p> to link with the shared (dynamic) library, or: </p><divclass="fragment"><divclass="line">target_link_libraries(myapp PUBLIC mimalloc-<spanclass="keyword">static</span>)</div>
</div><!-- fragment --><p> to link with the static library. See <code>test\CMakeLists.txt</code> for an example.</p>
<p>For best performance in C++ programs, it is also recommended to override the global <code>new</code> and <code>delete</code> operators. For convience, mimalloc provides <ahref="https://github.com/microsoft/mimalloc/blob/master/include/mimalloc-new-delete.h"><code>mimalloc-new-delete.h</code></a> which does this for you – just include it in a single(!) source file in your project.</p>
<p>In C++, mimalloc also provides the <code><aclass="el"href="group__cpp.html#structmi__stl__allocator"title="std::allocator implementation for mimalloc for use in STL containers.">mi_stl_allocator</a></code> struct which implements the <code>std::allocator</code> interface. For example: </p><divclass="fragment"><divclass="line">std::vector<some_struct, mi_stl_allocator<some_struct>> vec;</div>
<p>You can pass environment variables to print verbose messages (<code>MIMALLOC_VERBOSE=1</code>) and statistics (<code>MIMALLOC_SHOW_STATS=1</code>) (in the debug version): </p><divclass="fragment"><divclass="line">> env MIMALLOC_SHOW_STATS=1 ./cfrac 175451865205073170563711388363</div>
</div><!-- fragment --><p>The above model of using the <code>mi_</code> prefixed API is not always possible though in existing programs that already use the standard malloc interface, and another option is to override the standard malloc interface completely and redirect all calls to the <em>mimalloc</em> library instead.</p>
<liclass="footer">Generated by <ahref="https://www.doxygen.org/index.html"><imgclass="footer"src="doxygen.svg"width="104"height="31"alt="doxygen"/></a> 1.9.1 </li>