HandleAllocator

Struct HandleAllocator 

Source
pub struct HandleAllocator { /* private fields */ }
Expand description

Handle-based allocator with relocation support.

Implementations§

Source§

impl HandleAllocator

Source

pub fn new() -> Self

Create a new handle allocator.

Source

pub fn alloc<T>(&self) -> Option<Handle<T>>

Allocate memory and return a handle.

Source

pub fn alloc_with_options<T>( &self, relocatable: bool, on_relocate: Option<Box<dyn Fn(*mut u8, *mut u8) + Send + Sync>>, ) -> Option<Handle<T>>

Allocate with options.

Source

pub fn free<T>(&self, handle: Handle<T>)

Free a handle.

Source

pub fn resolve<T>(&self, handle: Handle<T>) -> Option<*const T>

Resolve a handle to a pointer.

Returns None if the handle is invalid or has been freed.

Source

pub fn resolve_mut<T>(&self, handle: Handle<T>) -> Option<*mut T>

Resolve a handle to a mutable pointer.

Source

pub fn is_valid<T>(&self, handle: Handle<T>) -> bool

Check if a handle is valid.

Source

pub fn pin<T>(&self, handle: Handle<T>)

Pin a handle to prevent relocation.

Source

pub fn unpin<T>(&self, handle: Handle<T>)

Unpin a handle to allow relocation.

Source

pub fn defragment(&self) -> usize

Perform defragmentation by relocating memory.

This is a simple compaction that moves relocatable allocations to reduce fragmentation. Returns the number of relocations performed.

Source

pub fn total_allocated(&self) -> u64

Get total allocated bytes.

Source

pub fn active_count(&self) -> u32

Get number of active handles.

Source

pub fn relocation_count(&self) -> u64

Get total relocations performed.

Source

pub fn stats(&self) -> HandleAllocatorStats

Get statistics about the handle allocator.

Trait Implementations§

Source§

impl Default for HandleAllocator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Send for HandleAllocator

Source§

impl Sync for HandleAllocator

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