purpleprotocol / mimalloc_rust

A Rust wrapper over Microsoft's MiMalloc memory allocator
MIT License
507 stars 43 forks source link

Add public API support for mi_posix_memalign #43

Closed jq-rs closed 3 years ago

jq-rs commented 3 years ago

Please add support for

    pub fn mi_calloc(count: usize, size: usize) -> *mut c_void;
    pub fn mi_posix_memalign(ptr: *mut *mut c_void, alignment: usize, size: usize) -> c_int;

so that this crate could be used with Rust compiler as an allocator replacement.

thomcc commented 3 years ago

mi_calloc is here: https://github.com/purpleprotocol/mimalloc_rust/blob/master/libmimalloc-sys/src/extended.rs#L17

In the same file and elsewhere you'll find many mi_aligned_alloc functions (search for aligned) which are more powerful and less error prone than the posix_memalign replacement.

jq-rs commented 3 years ago

Thanks. The external malloc API in rustc assumes support for posix_memalign. I am not aware of is it easy to change it to something else.

thomcc commented 3 years ago

Hm? I have a patch somewhere that does this, it's definitely possible.

Worth noting that overriding malloc statically only works well on non-apple unixes though.

thomcc commented 3 years ago

That said it's probably reasonable to add mi_posix_memalign for others who are stuck figuring out how to override something.

Note that you shouldn't use the override feature of this crate, though. It shouldn't have been added since for the most part it just enables functionality of the cmake build that is designed for producing a DLL that overrides malloc when set in the env.

jq-rs commented 3 years ago

Great, thanks! A new minor version published to crates.io would be awesome after this extension.