pub trait Region<H> {
type Pointers: Iterator<Item = *mut u8>;
// Required methods
fn allocate(&mut self, layout: Layout, header: H) -> Result<*mut u8, H>;
fn deallocate(&mut self, ptr: *mut u8) -> Option<H>;
fn has_allocated(&self, ptr: *mut u8) -> bool;
fn allocations(&self) -> Self::Pointers;
fn count(&self) -> usize;
// Provided method
fn deallocate_all(&mut self) -> DeallocateAll<'_, H, Self>
where Self: Sized { ... }
}Expand description
Represents a region of the memory. Objects can be allocated into this region. Regions can carry additional data with each allocation.
Required Associated Types§
Required Methods§
Sourcefn allocate(&mut self, layout: Layout, header: H) -> Result<*mut u8, H>
fn allocate(&mut self, layout: Layout, header: H) -> Result<*mut u8, H>
Finds a free location within this region that is:
- Properly aligned to
layout.align layout.sizebytes long
§Returns
The pointer is returned if the allocation is successful and the provided header is given back in the error if the allocation could not be done.
Sourcefn deallocate(&mut self, ptr: *mut u8) -> Option<H>
fn deallocate(&mut self, ptr: *mut u8) -> Option<H>
Sourcefn has_allocated(&self, ptr: *mut u8) -> bool
fn has_allocated(&self, ptr: *mut u8) -> bool
Checks whether the given pointer is allocated in this region.
Sourcefn allocations(&self) -> Self::Pointers
fn allocations(&self) -> Self::Pointers
Returns an iterator over all the allocations of this region.
Provided Methods§
Sourcefn deallocate_all(&mut self) -> DeallocateAll<'_, H, Self>where
Self: Sized,
fn deallocate_all(&mut self) -> DeallocateAll<'_, H, Self>where
Self: Sized,
Returns an iterator that causes all allocations to be deallocated. The iterator yield the headers.