pub struct FastAlloc { /* private fields */ }
Expand description
Fast allocator, effectively working as a cache.
This type implements Default and Copy. This type is intended to stored in a variable or a field in a struct before allocating code, and used as the seocnd argument in crate::boxed::Box::new_in and crate::vec::Vec::new_in.
crate::boxed::Box::new and crate::vec::Vec::new are slower than using this field because they use FastAlloc::default internally, which is slower than store FastAlloc in a variable.
§Misc
It implements std::alloc::Allocator
. So it can be used as the
second argument for std::boxed::Box
and
std::vec::Vec
. But you should prefer using
crate::boxed::Box
and crate::vec::Vec
, which is a wrapper around the
original types.
Implementations§
source§impl FastAlloc
impl FastAlloc
sourcepub const fn global() -> Self
pub const fn global() -> Self
crate::boxed::Box or crate::vec::Vec created with this instance is managed by the global allocator and it can outlive the crate::Allocator instance used for [Allocator::scope].
Trait Implementations§
source§impl Allocator for FastAlloc
impl Allocator for FastAlloc
source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
allocator_api
)allocate
, but also ensures that the returned memory is zero-initialized. Read moresource§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
allocator_api
)ptr
. Read moresource§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>
allocator_api
)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>
allocator_api
)grow
, but also ensures that the new contents are set to zero before being
returned. Read moreimpl Copy for FastAlloc
Auto Trait Implementations§
impl Freeze for FastAlloc
impl !RefUnwindSafe for FastAlloc
impl !Send for FastAlloc
impl !Sync for FastAlloc
impl Unpin for FastAlloc
impl !UnwindSafe for FastAlloc
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)