Code Monkey home page Code Monkey logo

mimallocator's Introduction

A Rust allocator backed by mimalloc

Travis-CI Status

This crates provides a Rust #[global_allocator] backed by mimalloc.

See also the mimalloc-sys crate providing raw FFI bindings to mimalloc.

Usage

# Cargo.toml
[dependencies]
mimallocator = "0.1" 
// main.rs
#[global_allocator]
static GLOBAL: mimallocator::Mimalloc = mimallocator::Mimalloc;

The mimalloc CMake configuration is exposed with these features

  • stats: Print statistics at program exit
  • secure: Build in secure mode
  • check_full: Enable full internal checks and asserts
# Cargo.toml
[dependencies]
mimallocator = { version = "0.1", features = ["secure", "stats", "check_full"] }

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in mimalloc-sys by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

mimallocator's People

Contributors

gnzlbg avatar ordian avatar osialr avatar rastertail avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mimallocator's Issues

Support building for aarch64-apple-darwin target

When building for the new aarch64-apple-darwin target for the new Mac M1 ARM CPUs with Nightly the C++ compilation fails with:

  running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-arch" "arm64" "-I" "mimalloc/include" "-I" "mimalloc/src" "-std=gnu11" "-Wall" "-Wextra" "-Wno-unknown-pragmas" "-ftls-model=initial-exec" "-Wno-invalid-memory-model" "-fstack-protector-all" "-fno-strict-aliasing" "-DMI_STATIC_LIB" "-DMI_DEBUG=3" "-DMI_SECURE=2" "-DMI_VERBOSE=0" "-DMI_STAT=0" "-o" "/Users/repi/git/rust/mimallocator/target/debug/build/mimalloc-sys-4a112146a3fd8379/out/mimalloc/src/static.o" "-c" "mimalloc/src/static.c"
  cargo:warning=warning: unknown warning option '-Wno-invalid-memory-model'; did you mean '-Wno-invalid-pp-token'? [-Wunknown-warning-option]
  cargo:warning=In file included from mimalloc/src/static.c:10:
  cargo:warning=mimalloc/include/mimalloc-internal.h:353:11: error: unknown token in expression
  cargo:warning=  __asm__("movq %%gs:0, %0" : "=r" (tid) : : );  // x86_64 macOS uses GS
  cargo:warning=          ^
  cargo:warning=<inline asm>:1:7: note: instantiated into assembly here
  cargo:warning=        movq %gs:0, x8
  cargo:warning=             ^
  cargo:warning=In file included from mimalloc/src/static.c:10:
  cargo:warning=mimalloc/include/mimalloc-internal.h:353:11: error: invalid operand
  cargo:warning=  __asm__("movq %%gs:0, %0" : "=r" (tid) : : );  // x86_64 macOS uses GS
  cargo:warning=          ^
  cargo:warning=<inline asm>:1:7: note: instantiated into assembly here
  cargo:warning=        movq %gs:0, x8
  cargo:warning=             ^
  cargo:warning=1 warning and 2 errors generated.
  exit code: 1

This is something we would like to support and probably would need an upgrade of latest mimalloc library and some smaller tweaks to get working.

Related: #9

Compile errors in Windows

Fails to compile with a few fatal errors on Windows using rustc 1.37.0-nightly (929b48ec9 2019-06-21), nightly-x86_64-pc-windows-msvc

error: failed to run custom build command for `mimalloc-sys v0.1.1`

Caused by:
  process didn't exit successfully: `F:\code\projects\testing\target\debug\build\mimalloc-sys-78444b9d7ac51358\build-script-build` (exit code: 101)
--- stdout
TARGET=x86_64-pc-windows-msvc
HOST=x86_64-pc-windows-msvc
PROFILE=debug
NUM_JOBS=32
OUT_DIR="F:\\code\\projects\\testing\\target\\debug\\build\\mimalloc-sys-5278bb05787e53d0\\out"
BUILD_DIR="F:\\code\\projects\\testing\\target\\debug\\build\\mimalloc-sys-5278bb05787e53d0\\out\\build"
SRC_DIR="C:\\Users\\novacrazy\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\mimalloc-sys-0.1.1"
mimalloc_src_dir="C:\\Users\\novacrazy\\.cargo\\registry\\src\\github.com-1ecc6299db9ec823\\mimalloc-sys-0.1.1\\mimalloc"
mimalloc_out_src_dir="F:\\code\\projects\\testing\\target\\debug\\build\\mimalloc-sys-5278bb05787e53d0\\out\\build\\mimalloc"
running: "cmake" "F:\\code\\projects\\testing\\target\\debug\\build\\mimalloc-sys-5278bb05787e53d0\\out\\build\\mimalloc" "-G" "Visual Studio 16 2019" "-Thost=x64" "-Ax64" "-DOVERRIDE=OFF"
"-DCMAKE_INSTALL_PREFIX=F:\\code\\projects\\testing\\target\\debug\\build\\mimalloc-sys-5278bb05787e53d0\\out" "-DCMAKE_C_FLAGS= /nologo /MD" "-DCMAKE_C_FLAGS_DEBUG= /nologo /MD" "-DCMAKE_CXX_FLAGS= /nologo /MD" "-DCMAKE_CXX_FLAGS_DEBUG= /nologo /MD" "-DCMAKE_BUILD_TYPE=Debug"
-- The C compiler identification is MSVC 19.20.27508.1
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.20.27508/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.20.27508/bin/Hostx64/x64/cl.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Build type specified as *** Debug ***
-- Output library name   : mimalloc-debug
-- Installation directory: lib/mimalloc-1.0
-- Configuring done
-- Generating done
-- Build files have been written to: F:/code/projects/testing/target/debug/build/mimalloc-sys-5278bb05787e53d0/out/build
running: "cmake" "--build" "." "--target" "install" "--config" "Debug" "--"
Microsoft (R) Build Engine version 16.0.461+g6ff56ef63c for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

  Checking Build System
  Building Custom Rule F:/code/projects/testing/target/debug/build/mimalloc-sys-5278bb05787e53d0/out/build/mimalloc/CMakeLists.txt
  stats.c
  os.c
  segment.c
  page.c
  alloc.c
  alloc-aligned.c
  heap.c
  options.c
  init.c
  Generating Code...
     Creating library F:/code/projects/testing/target/debug/build/mimalloc-sys-5278bb05787e53d0/out/build/Debug/mimalloc-debug.lib and object F:/code/projects/testing/target/debug/build/mimalloc-sys-5278bb05787e53d0/out/build/Debug/mimalloc-debug.exp
alloc.obj : error LNK2019: unresolved external symbol _mi_bin referenced in function _mi_page_malloc [F:\code\projects\testing\target\debug\build\mimalloc-sys-5278bb05787e53d0\out\build\mimalloc.vcxproj]
heap.obj : error LNK2001: unresolved external symbol _mi_bin [F:\code\projects\testing\target\debug\build\mimalloc-sys-5278bb05787e53d0\out\build\mimalloc.vcxproj]
F:\code\projects\testing\target\debug\build\mimalloc-sys-5278bb05787e53d0\out\build\Debug\mimalloc-debug.dll : fatal error LNK1120: 1 unresolved externals [F:\code\projects\testing\target\debug\build\mimalloc-sys-5278bb05787e53d0\out\build\mimalloc.vcxproj]
  Building Custom Rule F:/code/projects/testing/target/debug/build/mimalloc-sys-5278bb05787e53d0/out/build/mimalloc/CMakeLists.txt
  static.c
F:\code\projects\testing\target\debug\build\mimalloc-sys-5278bb05787e53d0\out\build\mimalloc\src\alloc-override.c(13): fatal error C1189: #error:  "It is only possible to override malloc on
Windows when building as a DLL (and linking the C runtime as a DLL)" [F:\code\projects\testing\target\debug\build\mimalloc-sys-5278bb05787e53d0\out\build\mimalloc-obj.vcxproj]
  Building Custom Rule F:/code/projects/testing/target/debug/build/mimalloc-sys-5278bb05787e53d0/out/build/mimalloc/CMakeLists.txt
  stats.c
  os.c
  segment.c
  page.c
  alloc.c
  alloc-aligned.c
  heap.c
  options.c
  init.c
  Generating Code...
  mimalloc-static.vcxproj -> F:\code\projects\testing\target\debug\build\mimalloc-sys-5278bb05787e53d0\out\build\Debug\mimalloc-debug.lib

--- stderr
CMake Warning:
  Manually-specified variables were not used by the project:

    CMAKE_CXX_FLAGS
    CMAKE_CXX_FLAGS_DEBUG


thread 'main' panicked at '
command did not execute successfully, got: exit code: 1

build script failed, must exit now', C:\Users\novacrazy\.cargo\registry\src\github.com-1ecc6299db9ec823\cmake-0.1.40\src\lib.rs:832:5
stack backtrace:
   0: backtrace::backtrace::trace_unsynchronized
             at C:\Users\appveyor\.cargo\registry\src\github.com-1ecc6299db9ec823\backtrace-0.3.29\src\backtrace\mod.rs:66
   1: std::sys_common::backtrace::_print
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\sys_common\backtrace.rs:47
   2: std::sys_common::backtrace::print
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\sys_common\backtrace.rs:36
   3: std::panicking::default_hook::{{closure}}
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\panicking.rs:198
   4: std::panicking::default_hook
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\panicking.rs:212
   5: std::panicking::rust_panic_with_hook
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\panicking.rs:475
   6: std::panicking::continue_panic_fmt
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\panicking.rs:382
   7: std::panicking::begin_panic_fmt
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\panicking.rs:337
   8: cmake::fail
             at C:\Users\novacrazy\.cargo\registry\src\github.com-1ecc6299db9ec823\cmake-0.1.40\src\lib.rs:832
   9: cmake::run
             at C:\Users\novacrazy\.cargo\registry\src\github.com-1ecc6299db9ec823\cmake-0.1.40\src\lib.rs:810
  10: cmake::Config::build
             at C:\Users\novacrazy\.cargo\registry\src\github.com-1ecc6299db9ec823\cmake-0.1.40\src\lib.rs:719
  11: build_script_build::main
             at .\build.rs:52
  12: std::rt::lang_start::{{closure}}<()>
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\src\libstd\rt.rs:64
  13: std::rt::lang_start_internal::{{closure}}
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\rt.rs:49
  14: std::panicking::try::do_call<closure,i32>
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\panicking.rs:294
  15: panic_unwind::__rust_maybe_catch_panic
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libpanic_unwind\lib.rs:82
  16: std::panicking::try
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\panicking.rs:273
  17: std::panic::catch_unwind
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\panic.rs:388
  18: std::rt::lang_start_internal
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\/src\libstd\rt.rs:48
  19: std::rt::lang_start<()>
             at /rustc/929b48ec98aaff2239257574b5897f419cec2647\src\libstd\rt.rs:64
  20: main
  21: invoke_main
             at d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  22: __scrt_common_main_seh
             at d:\agent\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  23: BaseThreadInitThunk
  24: RtlUserThreadStart

warning: build failed, waiting for other jobs to finish...
error: build failed

Maintenance status of this crate?

Hi, we've been happily using this crate for quite a while, and thanks for all the work on it!

Prefer over the, slightly more popular, mimalloc crate as this doesn't depend on and use CMake to build.

Haven't been any commits or upgrades for over a year though so wondering what the status of this crate is, would you be interested in additional maintainers to keep it up to date and tracking the latest mimalloc library updates?

Link error on OSX

Was trying this great wrapper on my macbook and found that there was not problem to run the program with cargo run but a link error of the libmimalloc_sys.dylib pop out when trying to execute the generated program directly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.