Struct fixed_bump::Bump [−][src]
A bump allocator that allocates memory in non-amortized O(1) (constant) time.
The allocator internally uses fixed-size chunks of memory. The size and
alignment of each chunk of memory is determined by the type parameters
Size
and Align
: the size is mem::size_of::<Size>()
and the
alignment is mem::align_of::<Align>()
. The default value of
Align
is Size
, so you can specify both the size and alignment with a
single type parameter.
A common use of this type, and the most space-efficient way to use it, is
to allocate many values of the same type (or at least the same size and
alignment). In this case, it may be convenient to specify the chunk size
using an array type: to use properly aligned chunks large enough to
allocate n
values of type T
, pass [T; n]
as the Size
parameter,
which will also be the Align
parameter by default.
Implementations
impl<Size, Align> Bump<Size, Align>
[src]
pub fn new() -> Self
[src]
Creates a new Bump
.
pub fn allocate(&self, layout: Layout) -> Option<NonNull<[u8]>>
[src]
Tries to allocate memory with a size and alignment matching layout
.
Returns a pointer to the memory on success, or None
on failure.
The memory is valid until the Bump
is dropped. Note that the
returned memory could be larger than layout.size()
.
This method is similar to Allocator::allocate
, except it returns an
Option
instead of a Result
.
Allocation is guaranteed to succeed, assuming the global allocator
succeeds, if layout.size()
is less than or equal to
mem::size_of::<Size>()
and layout.align()
is less than
or equal to mem::align_of::<Align>()
.
Allocation may fail, but is not guaranteed to fail, if
layout.align()
is greater than
mem::align_of::<Align>()
. Allocation is guaranteed to
fail if layout.size()
is greater than
mem::size_of::<Size>()
.
pub fn alloc_value<T>(&self, value: T) -> &mut T
[src]
Allocates a value of type T
.
The memory is initialized with value
and a reference to the value is
returned. Note that the value’s destructor will not be called
automatically.
Panics
Panics if Self::allocate
is not able to allocate memory matching
Layout::new::<T>()
. See Self::allocate
for
details regarding the circumstances in which allocation can fail.
For a non-panicking equivalent, see Self::try_alloc_value
.
pub fn try_alloc_value<T>(&self, value: T) -> Result<&mut T, T>
[src]
Tries to allocate a value of type T
.
If the allocation succeeds, the memory is initialized with value
and
a reference to the value is returned. Note that the value’s destructor
will not be called automatically.
Allocation succeeds if and only if Self::allocate
is able to
allocate memory matching Layout::new::<T>()
. See Self::allocate
for details regarding the circumstances in which allocation can fail.
Errors
If allocation fails, Err(value)
is returned.
Trait Implementations
impl<Size, Align> Allocator for Bump<Size, Align>
[src]
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
[src]
unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout)
[src]
pub fn allocate_zeroed(
&self,
layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
[src]
&self,
layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
pub unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
pub unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
pub unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
[src]
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout
) -> Result<NonNull<[u8]>, AllocError>
pub fn by_ref(&self) -> &Self
[src]
impl<Size, Align> Default for Bump<Size, Align>
[src]
Auto Trait Implementations
impl<Size, Align = Size> !Send for Bump<Size, Align>
impl<Size, Align = Size> !Sync for Bump<Size, Align>
impl<Size, Align> Unpin for Bump<Size, Align>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,