Re:Custom Allocators in Rust
by cbarrick on Saturday April 08, 2023 @09:00PM
(#35499192)
My problem with the allocaor-api is the "big box" problem.
That is, Box<T, A> is a struct containing both a pointer to T and an allocator handle A.
With an arena allocator, the handle A would be a pointer to the arena. But when using an arena, you don't actually need the box to retain the A after the initial allocation. Deallocation is a no-op; storing A is just wasting 8 bytes.
To get around this, Bumpalo (a prominent arena allocator) defines it's own box type rather than using the std Box. I'm not sure how I feel about that solution.
That is, Box<T, A> is a struct containing both a pointer to T and an allocator handle A.
With an arena allocator, the handle A would be a pointer to the arena. But when using an arena, you don't actually need the box to retain the A after the initial allocation. Deallocation is a no-op; storing A is just wasting 8 bytes.
To get around this, Bumpalo (a prominent arena allocator) defines it's own box type rather than using the std Box. I'm not sure how I feel about that solution.