Released YYYY-MM-DD.
- TODO (or remove section if none)
- The minimum supported Rust version (MSRV) is now 1.65.0.
- TODO (or remove section if none)
- TODO (or remove section if none)
- TODO (or remove section if none)
- TODO (or remove section if none)
Released 2023-09-14.
- Added the
std
cargo feature, which enables implementations ofstd
traits for various things. Right now that is juststd::io::Write
forbumpalo::collections::Vec
, but could be more in the future.
Released 2023-05-22.
- New
"allocator-api2"
feature enables the use of the allocator API on stable. This feature uses a crate that mirrors the API of the unstable Rustallocator_api
feature. If the feature is enabled, references toBump
will implementallocator_api2::Allocator
. This allowsBump
to be used as an allocator for collection types fromallocator-api2
and any other crates that supportallocator-api2
.
- The minimum supported Rust version (MSRV) is now 1.63.0.
Released 2023-05-09.
- Added
rust-version
metadata toCargo.toml
which helpscargo
with version resolution.
Released 2023-04-21.
- Fixed a bug where
Bump::try_with_capacity(n)
wheren > isize::MAX
could lead to attempts to create invalidLayout
s.
Released 2023-01-17.
- Added the
bumpalo::boxed::Box::bump
andbumpalo::collections::String::bump
getters to get the underlyingBump
that a string or box was allocated into.
- Some uses of
Box
that MIRI did not previously consider as UB are now reported as UB, andbumpalo
's internals have been adjusted to avoid the new UB.
Released 2022-10-18.
- Fixed a bug where when
std::vec::IntoIter
was ported tobumpalo::collections::vec::IntoIter
, it didn't get its underlyingBump
's lifetime threaded through. This meant thatrustc
was not checking the borrows forbumpalo::collections::IntoIter
and this could result in use-after-free bugs.
Released 2022-08-17.
- Added support for per-
Bump
allocation limits. These are enforced only in the slow path when allocating new chunks in theBump
, not in the bump allocation hot path, and therefore impose near zero overhead. - Added the
bumpalo::boxed::Box::into_inner
method.
- Updated to Rust 2021 edition.
- The minimum supported Rust version (MSRV) is now 1.56.0.
Released 2022-06-01.
- Implement
bumpalo::collections::FromIteratorIn
forOption
andResult
, just likecore
does forFromIterator
. - Implement
bumpalo::collections::FromIteratorIn
forbumpalo::boxed::Box<'a, [T]>
. - Added running tests under MIRI in CI for additional confidence in unsafe code.
- Publicly exposed
bumpalo::collections::Vec::drain_filter
since the correspondingstd::vec::Vec
method has stabilized.
Bump::new
will not allocate a backing chunk until the first allocation inside the bump arena now.
- Properly account for alignment changes when growing or shrinking an existing allocation.
- Removed all internal integer-to-pointer casts, to play better with UB checkers like MIRI.
Released 2022-01-06.
- Fixed link to logo in docs and README.md
Released 2022-01-05.
-
The minimum supported Rust version (MSRV) has been raised to Rust 1.54.0.
-
bumpalo::collections::Vec<T>
implements relevant traits for all arrays of any sizeN
via const generics. Previously, it was just arrays up to length 32. Similar forbumpalo::boxed::Box<[T; N]>
.
Released 2021-10-19.
-
Added the
CollectIn
andFromIteratorIn
traits to make building a collection from an iterator easier. These new traits live in thebumpalo::collections
module and are implemented bybumpalo::collections::{String,Vec}
. -
Added the
Bump::iter_allocated_chunks_raw
method, which is anunsafe
, raw version ofBump::iter_allocated_chunks
. The new method does not take an exclusive borrow of theBump
and yields raw pointer-and-length pairs for each chunk in the bump. It is the caller's responsibility to ensure that no allocation happens in theBump
while iterating over chunks and that there are no active borrows of allocated data if they want to turn any pointer-and-length pairs into slices.
Released 2021-09-17.
- The packaged crate uploaded to crates.io when
bumpalo
is published is now smaller, thanks to excluding unnecessary files.
Released 2020-05-28.
- Added
Borrow
andBorrowMut
trait implementations forbumpalo::collections::Vec
andbumpalo::collections::String
. #108
- When allocating a new chunk fails, don't immediately give up. Instead, try allocating a chunk that is half that size, and if that fails, then try half of that size, etc until either we successfully allocate a chunk or we fail to allocate the minimum chunk size and then finally give up. #111
Released 2020-02-18.
- Improved performance of
Bump
'sAllocator::grow_zeroed
trait method implementation. #99
Released 2020-01-29.
-
Added a few new flavors of allocation:
-
try_alloc
for fallible, by-value allocation -
try_alloc_with
for fallible allocation with an infallible initializer function -
alloc_try_with
for infallible allocation with a fallible initializer function -
try_alloc_try_with
method for fallible allocation with a fallible initializer function
We already have infallible, by-value allocation (
alloc
) and infallible allocation with an infallible initializer (alloc_with
). With these new methods, we now have every combination covered.Thanks to Tamme Schichler for contributing these methods!
-
Released 2020-01-22.
-
Added experimental, unstable support for the unstable, nightly Rust
allocator_api
feature.The
allocator_api
feature defines anAllocator
trait and exposes custom allocators forstd
types. Bumpalo has a matchingallocator_api
cargo feature to enable implementingAllocator
and usingBump
withstd
collections.First, enable the
allocator_api
feature in yourCargo.toml
:[dependencies] bumpalo = { version = "3.5", features = ["allocator_api"] }
Next, enable the
allocator_api
nightly Rust feature in yoursrc/lib.rs
orsrc/main.rs
:# #[cfg(feature = "allocator_api")] # { #![feature(allocator_api)] # }
Finally, use
std
collections withBump
, so that their internal heap allocations are made within the given bump arena:# #![cfg_attr(feature = "allocator_api", feature(allocator_api))] # #[cfg(feature = "allocator_api")] # { #![feature(allocator_api)] use bumpalo::Bump; // Create a new bump arena. let bump = Bump::new(); // Create a `Vec` whose elements are allocated within the bump arena. let mut v = Vec::new_in(&bump); v.push(0); v.push(1); v.push(2); # }
I'm very excited to see custom allocators in
std
coming along! Thanks to Arthur Gautier for implementing support for theallocator_api
feature for Bumpalo.
Released 2020-06-01.
- Added the
bumpalo::boxed::Box<T>
type. It is an owned pointer referencing a bump-allocated value, and it runsT
'sDrop
implementation on the referenced value when dropped. This type can be used by enabling the"boxed"
cargo feature flag.
Released 2020-05-13.
-
Added fallible allocation methods to
Bump
:try_new
,try_with_capacity
, andtry_alloc_layout
. -
Added
Bump::chunk_capacity
-
Added
bumpalo::collections::Vec::try_reserve[_exact]
Released 2020-03-24.
-
When
realloc
ing, if we allocate new space, we need to copy the old allocation's bytes into the new space. There areold_size
number of bytes in the old allocation, but we were accidentally copyingnew_size
number of bytes, which could lead to copying bytes into the realloc'd space from past the chunk that we're bump allocating out of, from unknown memory.If an attacker can cause
realloc
s, and can read therealoc
ed data back, this could allow them to read things from other regions of memory that they shouldn't be able to. For example, if some crypto keys happened to live in memory right after a chunk we were bump allocating out of, this could allow the attacker to read the crypto keys.Beyond just fixing the bug and adding a regression test, I've also taken two additional steps:
-
While we were already running the testsuite under
valgrind
in CI, becausevalgrind
exits with the same code that the program did, if there are invalid reads/writes that happen not to trigger a segfault, the program can still exit OK and we will be none the wiser. I've enabled the--error-exitcode=1
flag forvalgrind
in CI so that tests eagerly fail in these scenarios. -
I've written a quickcheck test to exercise
realloc
. Without the bug fix in this patch, this quickcheck immediately triggers invalid reads when run undervalgrind
. We didn't previously have quickchecks that exercisedrealloc
becauserealloc
isn't publicly exposed directly, and instead can only be indirectly called. This new quickcheck test exercisesrealloc
viabumpalo::collections::Vec::resize
andbumpalo::collections::Vec::shrink_to_fit
calls.
This bug was introduced in version 3.0.0.
See #69 for details.
-
Released 2020-02-07.
- Added the
bumpalo::collections::Vec::into_bump_slice_mut
method to turn abumpalo::collections::Vec<'bump, T>
into a&'bump mut [T]
.
Released 2020-01-07.
- The
bumpalo::collections::format!
macro did not used to accept a trailing comma likeformat!(in bump; "{}", 1,)
, but it does now.
Released 2020-01-03.
- The
bumpalo::collections::vec!
macro did not used to accept a trailing comma likevec![in bump; 1, 2,]
, but it does now.
Released 2019-12-27.
- Added the
Bump::allocated_bytes
diagnostic method for counting the total number of bytes aBump
has allocated.
Released 2019-12-20.
-
Added
Bump::alloc_str
for copying string slices into aBump
. -
Added
Bump::alloc_slice_copy
andBump::alloc_slice_clone
for copying or cloning slices into aBump
. -
Added
Bump::alloc_slice_fill_iter
for allocating a slice in theBump
from an iterator. -
Added
Bump::alloc_slice_fill_copy
andBump::alloc_slice_fill_clone
for creating slices of lengthn
that are filled with copies or clones of an initial element. -
Added
Bump::alloc_slice_fill_default
for creating slices of lengthn
with the element type's default instance. -
Added
Bump::alloc_slice_fill_with
for creating slices of lengthn
whose elements are initialized with a function or closure. -
Added
Bump::iter_allocated_chunks
as a replacement for the oldBump::each_allocated_chunk
. Theiter_allocated_chunks
version returns an iterator, which is more idiomatic than its old, callback-taking counterpart. Additionally,iter_allocated_chunks
exposes the chunks asMaybeUninit
s instead of slices, which makes it usable in more situations without triggering undefined behavior. See also the note about bump direction in the "changed" section; if you're iterating chunks, you're likely affected by that change! -
Added
Bump::with_capacity
so that you can pre-allocate a chunk with the requested space.
-
BREAKING: The direction we allocate within a chunk has changed. It used to be "upwards", from low addresses within a chunk towards high addresses. It is now "downwards", from high addresses towards lower addresses.
Additionally, the order in which we iterate over allocated chunks has changed! We used to iterate over chunks from oldest chunk to youngest chunk, and now we do the opposite: the youngest chunks are iterated over first, and the oldest chunks are iterated over last.
If you were using
Bump::each_allocated_chunk
to iterate over data that you had previously allocated, and you want to iterate in order of oldest-to-youngest allocation, you need to reverse the chunks iterator and also reverse the order in which you loop through the data within a chunk!For example, if you had this code:
unsafe { bump.each_allocated_chunk(|chunk| { for byte in chunk { // Touch each byte in oldest-to-youngest allocation order... } }); }
It should become this code:
let mut chunks: Vec<_> = bump.iter_allocated_chunks().collect(); chunks.reverse(); for chunk in chunks { for byte in chunk.iter().rev() { let byte = unsafe { byte.assume_init() }; // Touch each byte in oldest-to-youngest allocation order... } }
The good news is that this change yielded a speed up in allocation throughput of 3-19%!
See fitzgen#37 and https://fitzgeraldnick.com/2019/11/01/always-bump-downwards.html for details.
-
BREAKING: The
collections
cargo feature is no longer on by default. You must explicitly turn it on if you intend to use thebumpalo::collections
module. -
Bump::reset
will now retain only the last allocated chunk (the biggest), rather than only the first allocated chunk (the smallest). This should enableBump
to better adapt to workload sizes and quickly reach a steady state where new chunks are not requested from the global allocator.
-
The
Bump::each_allocated_chunk
method is removed in favor ofBump::iter_allocated_chunks
. Note that its safety requirements for reading from the allocated chunks are slightly different from the oldeach_allocated_chunk
: only up to 16-byte alignment is supported now. If you allocate anything with greater alignment than that into the bump arena, there might be uninitialized padding inserted in the chunks, and therefore it is no longer safe to read them viaMaybeUninit::assume_init
. See also the note about bump direction in the "changed" section; if you're iterating chunks, you're likely affected by that change! -
The
std
cargo feature has been removed, since this crate is now always no-std.
- Fixed a bug involving potential integer overflows with large requested allocation sizes.
Released 2019-08-19.
- Implement
Send
forBump
.
Released 2019-07-01.
- Add
alloc_slice_copy
andalloc_slice_clone
methods that allocate space for slices and either copy (with boundT: Copy
) or clone (with boundT: Clone
) the provided slice's data into the newly allocated space.
Released 2019-05-20.
- Fixed a bug where chunks were always deallocated with the default chunk layout, not the layout that the chunk was actually allocated with (i.e. if we started growing larger chunks with larger layouts, we would deallocate those chunks with an incorrect layout).
Released 2019-05-17.
- Added an implementation
Default
forBump
. - Made it so that if bump allocation within a chunk overflows, we still try to allocate a new chunk to bump out of for the requested allocation. This can avoid some OOMs in scenarios where the chunk we are currently allocating out of is very near the high end of the address space, and there is still available address space lower down for new chunks.
Released 2019-04-19.
- Added readme metadata to Cargo.toml so it shows up on crates.io
Released 2019-04-19.
- Added support for
realloc
ing in-place when the pointer beingrealloc
ed is the last allocation made from the bump arena. This should speed up variousString
,Vec
, andformat!
operations in many cases.
Released 2019-03-26.
- Add the
alloc_with
method, that (usually) avoids stack-allocating the allocated value and then moving it into the bump arena. This avoids potential stack overflows in release mode when allocating very large objects, and also somememcpy
calls. This is similar to thecopyless
crate. Read thealloc_with
doc comments and the original issue proposing this API for more.
Released 2019-03-18.
- Fix a regression from 2.2.1 where chunks were not always aligned to the chunk footer's alignment.
Released 2019-03-18.
- Fix a regression in 2.2.0 where newly allocated bump chunks could fail to have capacity for a large requested bump allocation in some corner cases.
Released 2019-03-15.
- Chunks in an arena now start out small, and double in size as more chunks are requested.
Released 2019-02-12.
- Added the
into_bump_slice
method onbumpalo::collections::Vec<T>
.
Released 2019-02-11.
- Removed the
BumpAllocSafe
trait. - Correctly detect overflows from large allocations and panic.
Released 2019-01-15.
- Fixed an overly-aggressive
debug_assert!
that had false positives. - Ported to Rust 2018 edition.
Released 2018-11-28.
- Added the
collections
module, which contains ports ofstd
's collection types that are compatible with backing their storage inBump
arenas. - Lifted the limits on size and alignment of allocations.