0

I was looking at Rust's Allocator trait. From my understanding, you give an allocator a length of memory and a word size to align to, and the allocator either gives you a pointer to the memory or an error. So clearly the custom Allocator is finding valid addresses in the memory somehow. How does the allocator know where in the heap it can allocate? Is there some "genesis" allocator that tells the custom Allocator which addresses it can take?

1 Answer 1

2

Custom allocators generally fall back to existing global allocators like libc malloc, and ultimately OS system calls like mmap on Linux to obtain allocatable memory. The point of custom allocators is to allow custom allocation strategies that might be more performant than the default ones for a specific use case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.