purpleprotocol / mimalloc_rust

A Rust wrapper over Microsoft's MiMalloc memory allocator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add public API support for mi_posix_memalign

jq-rs opened this issue · comments

commented

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.

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.

commented

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.

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.

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.

commented

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