fitzgen / bumpalo

A fast bump allocation arena for Rust
https://docs.rs/bumpalo
Apache License 2.0
1.36k stars 111 forks source link

Add reset_back #114

Closed quininer closed 11 months ago

quininer commented 3 years ago

This adds another reset method, which is different from reset in that it keeps last chunk on linked list instead of first chunk.

This is helpful for keep expected memory size after reset.

konsumlamm commented 2 years ago

I don't see the point of this new method. What advantage does it have over reset? What do you mean by "keep expected memory size"?

DJankauskas commented 2 years ago

I'm assuming what this does is instead of deallocating all previously allocated chunks other than the first one, it keeps all allocations, allowing you to reuse them when you reuse Bump. This seems useful to me, since if you're performing a bunch of tasks with similar memory needs, it might make sense to prevent having to fetch chunks from the global allocator over and over again. Would this not be so performant in practice? If not, this PR seems like something I might use in a project I'm working on right now (though I'd have to benchmark it).

Chaoses-Ib commented 11 months ago

This can be used to reserve capacity. Currently, one can only only reserve capacity at the start (by with_capacity or alloc + reset). With reset_back, one can reserve needed space by alloc + reset_back in the middle.

fitzgen commented 11 months ago

This is already the existing behavior of reset.