Struct acid_alloc::Bump
source · [−]pub struct Bump<A: BackingAllocator> { /* private fields */ }
Expand description
A bump allocator.
For a general discussion of bump allocation, see the module-level documentation.
Implementations
sourceimpl Bump<Raw>
impl Bump<Raw>
sourcepub unsafe fn new_raw(
region: NonNull<u8>,
layout: Layout
) -> Result<Bump<Raw>, AllocInitError>
pub unsafe fn new_raw(
region: NonNull<u8>,
layout: Layout
) -> Result<Bump<Raw>, AllocInitError>
Constructs a new Bump
from a raw pointer.
Safety
The caller must uphold the following invariants:
region
must be a pointer to a region that fitslayout
, and it must be valid for reads and writes for the entire size indicated bylayout
.- No references to the memory at
region
may exist when this function is called. - As long as the returned
Bump
exists, no accesses may be made to the memory atregion
except by way of methods on the returnedBump
.
sourceimpl Bump<Global>
impl Bump<Global>
sourcepub fn try_new(layout: Layout) -> Result<Bump<Global>, AllocInitError>
Available on crate feature alloc
only.
pub fn try_new(layout: Layout) -> Result<Bump<Global>, AllocInitError>
alloc
only.Attempts to construct a new Bump
backed by the global allocator.
The memory managed by this Bump
is allocated from the global allocator according to
layout
.
Errors
Returns an error if sufficient memory could not be allocated from the global allocator.
sourceimpl<A> Bump<A> where
A: Allocator,
impl<A> Bump<A> where
A: Allocator,
sourcepub fn try_new_in(
layout: Layout,
backing_allocator: A
) -> Result<Bump<A>, AllocInitError>
Available on crate feature unstable
only.
pub fn try_new_in(
layout: Layout,
backing_allocator: A
) -> Result<Bump<A>, AllocInitError>
unstable
only.Attempts to construct a new Bump
backed by backing_allocator
.
The memory managed by this Bump
is allocated from backing_allocator
according to
layout
.
Errors
Returns an error if sufficient memory could not be allocated from backing_allocator
.
sourceimpl<A> Bump<A> where
A: BackingAllocator,
impl<A> Bump<A> where
A: BackingAllocator,
sourcepub fn allocate(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
pub fn allocate(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Attempts to allocate a block of memory according to layout
.
Errors
Returns Err
if there is insufficient memory remaining to accommodate
layout
.
sourcepub unsafe fn deallocate(&mut self, ptr: NonNull<u8>)
pub unsafe fn deallocate(&mut self, ptr: NonNull<u8>)
Deallocates a block of memory.
This operation does not increase the amount of available memory unless
ptr
is the last outstanding allocation from this allocator.
Safety
ptr
must denote a block of memory currently allocated via this allocator.
sourcepub unsafe fn reset(&mut self)
pub unsafe fn reset(&mut self)
Resets the bump allocator.
This method invalidates all outstanding allocations from this allocator. The destructors of allocated objects will not be run.
Safety
The caller must uphold the following invariants:
- No references to memory allocated by this
Bump
may exist when the method is called. - Any pointers to memory previously allocated by this allocator may no longer be
dereferenced or passed to
Bump::deallocate()
.
Trait Implementations
sourceimpl<A> Debug for Bump<A> where
A: BackingAllocator,
impl<A> Debug for Bump<A> where
A: BackingAllocator,
Auto Trait Implementations
impl<A> RefUnwindSafe for Bump<A> where
A: RefUnwindSafe,
impl<A> !Send for Bump<A>
impl<A> !Sync for Bump<A>
impl<A> Unpin for Bump<A> where
A: Unpin,
impl<A> UnwindSafe for Bump<A> where
A: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more