Skip to content

Add malloc/free functions to std and use them consistently instead of C malloc #13616

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

Closed
brson opened this issue Apr 19, 2014 · 3 comments
Closed

Comments

@brson
Copy link
Contributor

brson commented Apr 19, 2014

These malloc/free would be guaranteed to allocate from Rusts heap. This isn't a big deal now but someday we'll have our own allocator and the existing calls to C malloc are going to create "dark" pools of memory that can't be instrumented like other Rust allocations and could potentially lead to other bugs.

@thestinger What do you think?

@thestinger
Copy link
Contributor

I was thinking that we should add back jemalloc, but this time as a submodule (it's even hosted on GitHub now) and without trying to replace malloc/realloc/free with it (by adding a prefix). This would give us the consistent jemalloc debugging API across platforms including heap profiling, zero/junk filling of memory, debugging, leak detection and statistics. It would also force us to fix any bugs where we're mixing malloc/free and our own allocators since it's going to die horribly.

We would be able to leverage the jemalloc-specific API to implement an allocator API like my proposal at rust-lang/rfcs#39. The API could just be marked experimental for now, because it's going to take a while to settle on details like the best way to report a usable size and whether passing a size to free should be optional, mandatory or done in some completely different way.

@flaper87
Copy link
Contributor

This sounds good. If we decide to add jemalloc back as a submodule, we must
be able to build Rust using a stable version of it (just concerned about
packaging).

I'll put more thoughts on this later, I'm AFK ATM.

@thestinger
Copy link
Contributor

Well, I expect that we'll check out the latest stable tag and add an --enable-external-jemalloc switch to configure.

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

3 participants