A crate feature to implement the libc malloc API
maxbrunsfeld opened this issue · 4 comments
Great project!
What do you think about adding a feature flag that causes this crate to implement the libc malloc API (i.e. extern "C"
malloc
, realloc
, calloc
, free
, and maybe posix_memalign
) for linked C/C++ code to consume?
I have a mixed Rust/C project that I'm compiling to Wasm. I need a malloc
implementation, because I'd like to use wasm32-unknown-unknown
and not Emscripten, so that I can use wasm-bindgen
. Also, to reduce the binary size, I'd like for my Rust and C code to share the same allocator.
I've hacked this in locally, so if you're in favor of it, I'd be up for submitting a PR.
An interesting idea! I think though you probably don't want to do this since it introduces two allocators, but rather you probably want to wrap std::alloc::System
to ensure everything is using the same allocator?
I think though you probably don't want to do this since it introduces two allocators
I thought that this actually was the same allocator that Rust code would be using when compiling with wasm-bindgen. I see a bunch of dlmalloc
symbols in my .wasm
file.
Will it not work to add an explicit dependency on this crate (so that I can enable this feature)?
It's true yeah that libstd uses dlmalloc, but if you depend on this crate from crates.io that pulls in two versions because you're not using the same version as libstd. By using System
though you're guaranteed to use the same version.
Oh ok, thanks for the explanation; I didn't realize System
was publicly accessible like that. Sorry for the noise.