[−][src]Struct alloc_compose::Region
Allocator over an user-defined region of memory.
Examples
#![feature(allocator_api)] use alloc_compose::{Owns, Region}; use core::alloc::{AllocInit, AllocRef, Layout}; let mut data = [0; 64]; let mut region = Region::new(&mut data); let memory = region.alloc(Layout::new::<u32>(), AllocInit::Uninitialized)?; assert!(region.owns(memory));
It's possible to deallocate the latest memory block allocated:
unsafe { region.dealloc(memory.ptr, Layout::new::<u32>()) }; assert!(!region.owns(memory));
Methods
impl<'a> Region<'a>
[src]
pub fn new(data: &'a mut [u8]) -> Self
[src]
pub const fn capacity(&self) -> usize
[src]
Returns the total capacity available in this allocator.
pub fn capacity_left(&self) -> usize
[src]
Returns the free capacity left for allocating.
pub fn reset(&mut self)
[src]
Resets the allocator.
This implies, that capacity()
and capacity_left()
are equal afterwards.
pub fn is_last_block(&self, memory: MemoryBlock) -> bool
[src]
Checks if memory
is the latest block, which was allocated.
For those blocks, it's possible to deallocate them or to grow
or shrink them in place.
Trait Implementations
impl<'_> AllocRef for Region<'_>
[src]
fn alloc(
&mut self,
layout: Layout,
init: AllocInit
) -> Result<MemoryBlock, AllocErr>
[src]
&mut self,
layout: Layout,
init: AllocInit
) -> Result<MemoryBlock, AllocErr>
unsafe fn dealloc(&mut self, ptr: NonNull<u8>, layout: Layout)
[src]
unsafe fn grow(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
placement: ReallocPlacement,
init: AllocInit
) -> Result<MemoryBlock, AllocErr>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
placement: ReallocPlacement,
init: AllocInit
) -> Result<MemoryBlock, AllocErr>
unsafe fn shrink(
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
placement: ReallocPlacement
) -> Result<MemoryBlock, AllocErr>
[src]
&mut self,
ptr: NonNull<u8>,
layout: Layout,
new_size: usize,
placement: ReallocPlacement
) -> Result<MemoryBlock, AllocErr>
fn by_ref(&mut self) -> &mut Self
[src]
impl<'_> Debug for Region<'_>
[src]
impl<'_> Owns for Region<'_>
[src]
fn owns(&self, memory: MemoryBlock) -> bool
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,