Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A crate feature to implement the libc malloc API #9

Closed
maxbrunsfeld opened this issue Oct 2, 2019 · 4 comments
Closed

A crate feature to implement the libc malloc API #9

maxbrunsfeld opened this issue Oct 2, 2019 · 4 comments

Comments

@maxbrunsfeld
Copy link

maxbrunsfeld commented Oct 2, 2019

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.

@alexcrichton
Copy link
Owner

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?

@maxbrunsfeld
Copy link
Author

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)?

@alexcrichton
Copy link
Owner

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.

@maxbrunsfeld
Copy link
Author

Oh ok, thanks for the explanation; I didn't realize System was publicly accessible like that. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants