pub struct Allocator { /* private fields */ }Expand description
Implementations§
Source§impl Allocator
impl Allocator
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset this allocator.
Performs mass deallocation on everything allocated in this arena by resetting the pointer
into the underlying chunk of memory to the start of the chunk.
Does not run any Drop implementations on deallocated objects.
If this arena has allocated multiple chunks to bump allocate into, then the excess chunks are returned to the global allocator.
§Example
use oxc_allocator::Allocator;
let mut allocator = Allocator::default();
// Allocate a bunch of things.
{
for i in 0..100 {
allocator.alloc(i);
}
}
// Reset the arena.
allocator.reset();
// Allocate some new things in the space previously occupied by the
// original things.
for j in 200..400 {
allocator.alloc(j);
}Trait Implementations§
Source§impl Allocator for &Allocator
impl Allocator for &Allocator
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Attempts to allocate a block of memory. Read more
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
Deallocates the memory referenced by
ptr. Read moreSource§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Attempts to shrink the memory block. Read more
Source§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Attempts to extend the memory block. Read more
Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
Behaves like
grow, but also ensures that the new contents are set to zero before being
returned. Read moreSource§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
Behaves like
allocate, but also ensures that the returned memory is zero-initialized. Read moreimpl Send for Allocator
SAFETY: Not actually safe, but for enabling Send for downstream crates.
impl Sync for Allocator
SAFETY: Not actually safe, but for enabling Sync for downstream crates.
Auto Trait Implementations§
impl !Freeze for Allocator
impl !RefUnwindSafe for Allocator
impl Unpin for Allocator
impl !UnwindSafe for Allocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more