[−][src]Struct polymorph_allocator::Allocator
Simple memory allocator
Fields
first_region: usize
Address of the header for the first known memory region.
Implementations
impl Allocator
[src]
pub const fn empty() -> Allocator
[src]
Creates an empty Allocator with no regions.
pub fn min_allocation_size() -> usize
[src]
The minimum size of an allocation.
pub unsafe fn add_region(&mut self, addr: usize, size: usize)
[src]
Adds a new memory region to this Allocator with the given addr
and
size
.
Unsafety
This function must only be called once for a given addr
and size
pair, and should never be called with a subregion of memory from
addr
to addr + size - 1
given in a previous call.
pub fn iter(&self) -> AllocatorRegionIterator
[src]
Returns an iterator over the memory regions known to this Allocator.
pub fn get_region_first(&self) -> Option<&mut Region>
[src]
Returns the region header for the first known region.
pub fn get_region_first_free(&self, size: usize) -> Option<&mut Region>
[src]
Returns the region header for the first known region that is not set
as used, and is large enough to contain size
.
pub fn get_region_for_ptr(&self, ptr: *mut u8) -> Option<&mut Region>
[src]
Returns the region header associated with a given header pointer ptr
.
pub fn get_region_for_data_ptr(&self, ptr: *mut u8) -> Option<&mut Region>
[src]
Returns the region header associated with a given data pointer ptr
.
pub fn combine_regions(&self, ptr: *mut u8)
[src]
Combines free regions that are adjacent to the region with header pointer ptr
.
pub fn allocate(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr>
[src]
Allocates a region of memory using the size and alignment from the
given layout
, and returns a pointer to it as a NonNull<u8>
.
Errors
Returns an AllocErr
if there was not enough free memory to allocate
a region for the requested layout.
pub fn deallocate(&mut self, ptr: NonNull<u8>, _layout: Layout)
[src]
Deallocate the region with the data pointer ptr
, and recombines
regions around it.
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>,