pub struct GpuMemoryPool { /* private fields */ }Expand description
GPU memory pool allocator.
Implementations§
Source§impl GpuMemoryPool
impl GpuMemoryPool
Sourcepub fn new(block_size: usize) -> Self
pub fn new(block_size: usize) -> Self
Create a new pool.
block_size– size of each new backing block in bytes.
Sourcepub fn alloc(
&mut self,
size: usize,
alignment: Alignment,
) -> Option<AllocationHandle>
pub fn alloc( &mut self, size: usize, alignment: Alignment, ) -> Option<AllocationHandle>
Allocate size bytes with the given alignment.
Returns an AllocationHandle on success. If no existing block can
satisfy the request, a new backing block is created.
Sourcepub fn free(&mut self, handle: &AllocationHandle)
pub fn free(&mut self, handle: &AllocationHandle)
Free a previously allocated handle.
Sourcepub fn block_count(&self) -> usize
pub fn block_count(&self) -> usize
Total number of backing blocks.
Sourcepub fn free_bytes(&self) -> usize
pub fn free_bytes(&self) -> usize
Total free bytes across all blocks.
Sourcepub fn defragment(&mut self) -> DefragResult
pub fn defragment(&mut self) -> DefragResult
Defragment the pool by coalescing free ranges in all blocks and removing completely empty blocks.
This operation is O(B * R log R) where B = block count, R = free ranges. Call periodically in long-running sessions to reduce fragmentation.
Returns a DefragResult describing the work performed.
Sourcepub fn compact(&mut self) -> Option<CompactionPlan>
pub fn compact(&mut self) -> Option<CompactionPlan>
Compact the pool by migrating allocations from sparsely-used blocks into denser blocks, freeing up empty blocks.
This is a more aggressive form of defragment() — it returns a list
of migrations (old_handle, new_handle) that the caller must apply to
move data from old offsets to new offsets.
Returns None if compaction is not possible or not beneficial.
Sourcepub fn fragmentation_ratio(&self) -> f64
pub fn fragmentation_ratio(&self) -> f64
Calculate the fragmentation ratio (0.0 = no fragmentation, 1.0 = fully fragmented).
Defined as: 1 - (largest_free_contiguous / total_free). A value of 0.0 means all free memory is in one contiguous block.
Auto Trait Implementations§
impl Freeze for GpuMemoryPool
impl RefUnwindSafe for GpuMemoryPool
impl Send for GpuMemoryPool
impl Sync for GpuMemoryPool
impl Unpin for GpuMemoryPool
impl UnsafeUnpin for GpuMemoryPool
impl UnwindSafe for GpuMemoryPool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more