Rust-allocator based malloc and free

I have a C library that can take pointers to malloc and free replacements for custom allocator. I thought it'd be cool to use Rust's allocator, so that the C library can reuse jemalloc instead of libc malloc.

Does Rust expose its "raw" malloc/free anywhere? Or should I steal memory from a Vec instead?

The Rust allocator has a sized delete/free operation, so it can be implemented on top of malloc/free, but not the other way round.

I still need this. I could work around lack of size by storing size in the begging of the buffer (in free reading it from ptr[-1]).

But which functions allocate and free in Rust?

I think you're looking for .

Yeah. What a fancy API, with alignment, padding, etc.