Skip to main content

DefragmentationContext

Struct DefragmentationContext 

Source
pub struct DefragmentationContext<'allocator, 'device> { /* private fields */ }
Expand description

Persistent multi-pass relocation state with one exclusive allocator borrow. Ignored allocations stay immovable for subsequent passes in this context. Each pass must be explicitly resolved and finished; neither context nor pass Drop submits, waits or destroys native resources. An abandoned unresolved pass leaks its reservations, as documented by DefragmentationPass.

Initial per-domain order, Balanced averages and Extensive evacuation/packing phases persist across passes. Extensive holds its blocks for reuse until explicit finish; Drop clears host holds but never frees native memory.

Implementations§

Source§

impl<'allocator, 'device> DefragmentationContext<'allocator, 'device>

Source

pub fn new( allocator: &'allocator mut Allocator<'device>, info: &DefragmentationInfo<'_>, ) -> Result<Self, AllocError>

Retain one allocator and optional TLSF pool for successive bounded passes. No placement reservation or native effect occurs until begin_pass.

§Errors

Rejects closed/foreign/stale pools, linear-pool relocation and host metadata failure.

Source

pub unsafe fn begin_pass( &mut self, ) -> Result<DefragmentationPass<'_, 'device>, AllocError>

Reserve another bounded pass, excluding previously ignored source identities. Extensive may move into a later evacuated block to pack compatible classes. is_empty means this pass proposed no move under its policy and copy limits.

§Errors

Preserves policy/host metadata/planning errors without changing source storage.

§Safety

Same live-source, completed-copy and explicit move-resolution obligations as mem::begin_defragmentation. Finish/abort every pass before beginning another.

Source

pub unsafe fn begin_pass_with_break( &mut self, should_break: &mut dyn FnMut() -> bool, ) -> Result<DefragmentationPass<'_, 'device>, AllocError>

Plan the next pass with a stop predicate borrowed only for this call. True preserves already proposed moves for resolution; was_interrupted distinguishes a stopped empty pass from completed scheduling. A later pass can use a different predicate; this context retains policy and ignored state.

§Safety

Same source/alias/mapped-pointer and explicit resolution contract as begin_pass.

Source

pub fn statistics(&self) -> DefragmentationStats

Totals from explicitly finished passes, never uncommitted proposals.

Source

pub fn ignored_allocations(&self) -> usize

Source

pub fn finish(&mut self) -> Result<DefragmentationStats, AllocError>

Complete the context after all passes are resolved and finished. Extensive explicitly releases held empty blocks above pool minimums here; freed native block/byte counts are included in the returned total statistics.

Trait Implementations§

Source§

impl Drop for DefragmentationContext<'_, '_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'allocator, 'device> !Send for DefragmentationContext<'allocator, 'device>

§

impl<'allocator, 'device> !Sync for DefragmentationContext<'allocator, 'device>

§

impl<'allocator, 'device> !UnwindSafe for DefragmentationContext<'allocator, 'device>

§

impl<'allocator, 'device> Forget for DefragmentationContext<'allocator, 'device>

§

impl<'allocator, 'device> Freeze for DefragmentationContext<'allocator, 'device>

§

impl<'allocator, 'device> Move for DefragmentationContext<'allocator, 'device>

§

impl<'allocator, 'device> RefUnwindSafe for DefragmentationContext<'allocator, 'device>

§

impl<'allocator, 'device> Unpin for DefragmentationContext<'allocator, 'device>

§

impl<'allocator, 'device> UnsafeUnpin for DefragmentationContext<'allocator, 'device>

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.