Closed morrisonlevi closed 1 year ago
bumpalo
already internally is rounding to "about a page" to play nice with the underlying allocator, so there is no need to expose it to users to attempt to handle this twice.
https://github.com/fitzgen/bumpalo/blob/19891eed44c866c4efd91d331a2ad5e6d6bcb0ae/src/lib.rs#L652
@fitzgen At least for the initial allocation, this doesn't seem to be true:
let arena = Bump::new();
let _ = arena.alloc(true);
let capacity = arena.chunk_capacity();
assert_eq!(4096-64-1, capacity);
Fails with:
left: `4031`,
right: `448`,
When the capacity is below a page in size it does simple doubling, after which point the rounding to page sizes (while leaving a little room for malloc overhead) kicks in.
See the comment just above the line of code I linked and that whole general bit of code
Yes, I understand that. But I don't want that behavior. I want to start at 1 page, and I don't know the overhead. What do you recommend for this case? Bump::with_capacity(4000)
?
In general, you're better off letting the dynamic chunk growth happen and adapt its strategy but if you absolutely need to start with ~a page, that should work fine.
When setting the Bump capacity, it would be nice to have a constant (or helper function) for allocating about one "page" worth of memory e.g.
Essentially, I don't care about the exact value, I just want bumpalo to have nice chunk sizes as far as the underlying allocator is concerned. I just don't know how to tell it to do that, other than by experimentation, which could be broken by implementation changes.