Skip to main content

Crate bump_recycle

Crate bump_recycle 

Source
Expand description

ReBump is much like bumpalo - except it reuses deallocated memory.

To put it dramatically - you basically don’t need nor reset, nor scopes - if you can tolerate all your allocation sizes being aligned to POT, and you allocate/deallocate more or less the same layout sizes.

Also, being able to reclaim deallocated blocks - means that it can be used inside your struct as an internal memory storage source, for all data and containers. On top of allocation/deallocation speed - that grants some memory locality.

See /examples for motivation examples.

§How it works

All memory allocated in POT size blocks.

When you deallocate - that block stored in intrusive linked list of blocks of the same size. Roots of lists stored in a small [*mut u8; 32] table - each table index corresponds to 2^index block size.

When you allocate - ReBump first look in a table for requested size (aligned to POT) - if there is one - it returns it, if no - it works exactly as bumpalo.

§Design choice

ReBump does not unify or split deallocated blocks - thus it can only reuse blocks of these exact sizes (aligned to POT). This is deliberately to simplify allocation process. Since blocks aligned to POT sizes - when you work with growing Vecs - you most likely will have blocks of needed sizes.

§Align

All internal chunks and blocks have 8 bytes align. Requested layouts with align > 8 will store additional information block (8 bytes) before the begin of data block.

§Maximum size

Maximum size this allocator can allocate is u32::MAX * 8 bytes.

Open an issue if you need bigger allocations.

§ZST

ZST does not handled specially. Allocator will use minimal possible block (ALIGN size) for all ZST allocations. This is to minimize branching. Such behavior does not brake allocator_api contract.

Open an issue - if you think this should be different.

§Allocator

ReBump can use user provided allocator itself. User provided allocator must implement crate’s Allocator trait. Use wrappers from alloc module for that:

use bump_recycle::ReBump;
use bump_recycle::alloc::AllocatorApiStd;

let bumpalo = bumpalo::Bump::new();
let allocator = ReBump::new_in(AllocatorApiStd(&bumpalo));

§Features

Modules§

alloc

Structs§

ReBump