Skip to content

Commit

Permalink
Add a with_capacity function
Browse files Browse the repository at this point in the history
  • Loading branch information
TethysSvensson committed Oct 29, 2019
1 parent 7ac4a53 commit 92d2842
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ impl Bump {
}
}

/// Construct a new arena with the specified capacity to bump allocate into.
///
/// ## Example
///
/// ```
/// let bump = bumpalo::Bump::with_capacity(100);
/// # let _ = bump;
/// ```
pub fn with_capacity(capacity: usize) -> Bump {
let layout = if capacity + mem::size_of::<ChunkFooter>() < DEFAULT_CHUNK_SIZE_WITH_FOOTER {
None
} else {
Some((0, unsafe { layout_from_size_align(capacity, 1) }))
};
let chunk_footer = Self::new_chunk(layout);
Bump {
current_chunk_footer: Cell::new(chunk_footer),
all_chunk_footers: Cell::new(chunk_footer),
}
}

/// Allocate a new chunk and return its initialized footer.
///
/// If given, `layouts` is a tuple of the current chunk size and the
Expand Down

0 comments on commit 92d2842

Please sign in to comment.