slab_allocator::slab

Struct Slab

Source
pub struct Slab {
    pub block_size: usize,
    pub block_num: usize,
    free_list: FreeList,
}
Expand description

Slab 内存块分配器。

§字段

  • block_size:每个内存块的大小
  • block_num:内存块的数量
  • free_list:空闲内存块列表

Fields§

§block_size: usize§block_num: usize§free_list: FreeList

Implementations§

Source§

impl Slab

Source

pub const fn empty(block_size: usize) -> Self

创建一个新的空的 Slab 实例。

§参数
  • block_size:每个内存块的大小
§返回

具有指定块大小的新 Slab 空实例,其中没有内存块。

Source

pub fn new(start: Address, block_size: usize, block_num: usize) -> Self

创建一个新的 Slab 实例。

§参数
  • start:内存块的起始地址
  • block_size:每个内存块的大小
  • block_num:内存块的数量
§返回

具有指定参数的新 Slab 实例。

Source

pub fn grow(&mut self, start: Address, slab_size: usize)

扩展 Slab 实例的内存块。

§参数
  • start:新内存块的起始地址
  • slab_size:新内存块的总大小
Source

pub fn alloc(&mut self) -> Result<NonNull<u8>, AllocError>

从 Slab 实例中分配一个内存块。

§返回

如果成功分配内存块,则返回内存块的地址;否则返回 None。

Source

pub fn dealloc(&mut self, addr: NonNull<u8>)

将一个内存块释放回 Slab 实例。

§参数
  • addr:要释放的内存块的地址

Auto Trait Implementations§

§

impl Freeze for Slab

§

impl RefUnwindSafe for Slab

§

impl Send for Slab

§

impl Sync for Slab

§

impl Unpin for Slab

§

impl !UnwindSafe for Slab

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<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.