Struct MemPool

Source
pub struct MemPool<A: Allocator = PoolAlloc>(/* private fields */);
Expand description

单线程分配资源,不支持Sync, 但只是Send. 因为已分配资源析构的时候并不会访问Pool 所有内存都在Pool析构的时候集中释放,不存在多线程访问的情况

Implementations§

Source§

impl Pool<PoolAlloc>

Source

pub fn new(page_size: usize) -> Self

Source

pub fn new_boxed(page_size: usize) -> Result<BoxedPool>

Source§

impl<A: Allocator> Pool<A>

Source

pub fn reset_boxed(boxed: Boxed<'_, Self, NullAlloc>) -> BoxedPool<A>

Source

pub fn reset(self) -> Self

Source§

impl<A: Allocator> Pool<A>

Source

pub unsafe fn from_raw(raw: *mut Self) -> BoxedPool<A>

§Safety

使用者保证raw一定是从leak返回的指针

Source

pub fn stat(&self) -> Stat

Source

pub fn new_in(alloc: A, page_size: usize) -> Self

Source

pub fn add_page_buf(&self, buf: &'static [u8])

Source

pub fn new_boxed_in<'a>( alloc: A, page_size: usize, ) -> Result<Boxed<'a, Self, NullAlloc>>

Trait Implementations§

Source§

impl<A: Allocator> Allocator for Pool<A>

Source§

unsafe fn alloc_buf<F>(&self, layout: Layout, f: F) -> Result<NonNull<[u8]>>
where F: FnOnce(NonNull<[u8]>) -> Result<()>,

Safety Read more
Source§

unsafe fn free_buf(&self, ptr: NonNull<[u8]>, layout: Layout)

Safety Read more
Source§

impl<A: Allocator> GlobalAlloc for Pool<A>

Source§

unsafe fn alloc(&self, layout: Layout) -> *mut u8

Allocates memory as described by the given layout. Read more
Source§

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

Deallocates the block of memory at the given ptr pointer with the given layout. Read more
1.28.0 · Source§

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8

Behaves like alloc, but also ensures that the contents are set to zero before being returned. Read more
1.28.0 · Source§

unsafe fn realloc( &self, ptr: *mut u8, layout: Layout, new_size: usize, ) -> *mut u8

Shrinks or grows a block of memory to the given new_size in bytes. The block is described by the given ptr pointer and layout. Read more
Source§

impl<A: Allocator> Pool for Pool<A>

Source§

impl<A: Allocator + Send> Send for Pool<A>

Auto Trait Implementations§

§

impl<A = PoolAlloc> !Freeze for Pool<A>

§

impl<A = PoolAlloc> !RefUnwindSafe for Pool<A>

§

impl<A = PoolAlloc> !Sync for Pool<A>

§

impl<A> Unpin for Pool<A>
where A: Unpin,

§

impl<A> UnwindSafe for Pool<A>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A> GenericAlloc for A
where A: Allocator + ?Sized,

Source§

unsafe fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, Error>

Safety Read more
Source§

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout)

Safety Read more
Source§

unsafe fn init<T>(&self, val: T) -> Result<NonNull<T>, Error>

Safety Read more
Source§

unsafe fn alloc_then<T, F>(&self, f: F) -> Result<NonNull<T>, Error>
where F: FnOnce() -> Result<T, Error>,

Safety Read more
Source§

unsafe fn init_slice<T>( &self, len: usize, val: T, ) -> Result<NonNull<[T]>, Error>
where T: Clone,

Safety Read more
Source§

unsafe fn alloc_slice_then<T, F>( &self, len: usize, f: F, ) -> Result<NonNull<[T]>, Error>
where F: FnMut(usize) -> Result<T, Error>,

Safety Read more
Source§

unsafe fn zeroed<T>(&self) -> Result<NonNull<MaybeUninit<T>>, Error>

Safety Read more
Source§

unsafe fn zeroed_slice<T>( &self, len: usize, ) -> Result<NonNull<[MaybeUninit<T>]>, Error>

Safety Read more
Source§

unsafe fn uninit<T>(&self) -> Result<NonNull<MaybeUninit<T>>, Error>

Safety Read more
Source§

unsafe fn uninit_slice<T>( &self, len: usize, ) -> Result<NonNull<[MaybeUninit<T>]>, Error>

Safety Read more
Source§

unsafe fn release<T>(&self, ptr: NonNull<T>)

Safety Read more
Source§

unsafe fn release_with<T>(&self, ptr: NonNull<T>, layout: Layout)
where T: ?Sized,

Safety Read more
Source§

unsafe fn release_slice<T>(&self, ptr: NonNull<[T]>)

Safety Read more
Source§

unsafe fn release_slice_with<T>(&self, ptr: NonNull<[T]>, layout: Layout)

Safety Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.