Skip to main content

BufferMemoryAllocator

Struct BufferMemoryAllocator 

Source
pub struct BufferMemoryAllocator<'a>(/* private fields */);
Expand description

A class that does simple allocation based on a size and returns the pointer to the memory address. It bookmarks a buffer with certain size. The allocation is simply checking space and growing the cur_ pointer with each allocation request.

Implementations§

Source§

impl<'a> BufferMemoryAllocator<'a>

Source

pub fn new(buffer: &'a mut [u8]) -> Self

Constructs a new memory allocator using a fixed-size buffer.

§Arguments
  • buffer - The buffer to use for memory allocation.
§Panics

Panics if the buffer is larger than u32::MAX bytes.

Trait Implementations§

Source§

impl<'a> MemoryAllocator<'a> for BufferMemoryAllocator<'a>

Source§

fn allocate_raw(&self, size: usize, alignment: usize) -> Option<&mut [u8]>

Allocates memory of a certain size and alignment. Read more

Auto Trait Implementations§

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<'a, T> MemoryAllocatorExt<'a> for T
where T: MemoryAllocator<'a> + ?Sized,

Source§

fn allocate_uninit<T>(&self) -> Option<&mut MaybeUninit<T>>

Allocates memory for a type T with uninitialized memory. Read more
Source§

fn allocate<T>(&self) -> Option<&mut T>
where T: NoDrop + Default,

Allocates memory for a type T and initializes it with Default::default(). Read more
Source§

fn allocate_pinned<T>(&self) -> Option<Pin<&mut T>>
where T: NoDrop + Default,

Allocates a pinned memory for a type T and initializes it with Default::default(). Read more
Source§

fn allocate_arr<T>(&self, len: usize) -> Option<&mut [T]>
where T: NoDrop + Default,

Allocates memory for an array of type T and initializes each element with Default::default(). Read more
Source§

fn allocate_arr_fn<T>( &self, len: usize, f: impl Fn(usize) -> T, ) -> Option<&mut [T]>
where T: NoDrop,

Allocates memory for an array of type T and initializes each element with the result of the closure f. Read more
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.