Making a custom allocator?

Does anybody know how one would go about implementing a custom allocator in an idiomatic way? For example simple integration into the rust's global allocator, etc.

Rust 1.28 made the global allocator trait stable.

The actual trait documentation is probably the best source of information of how to structure it.

If you mean how you would go about actually allocating it, that becomes a question of what you need. A lot of allocators in C++ just wrap the default heap allocation system and redistribute it, which means you could do the same in Rust (there's a very common Vec hack to allocate raw memory in blocks). Personally I would look at my platform to determine what needs to be done and abstract on a per-platform basis (if that's what is needed).

1 Like

Oh my gosh thank you so much. I don't know why I was having so much trouble finding this.

1 Like