StreamingAllocator

Struct StreamingAllocator 

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

Streaming allocator for large assets.

Implementations§

Source§

impl StreamingAllocator

Source

pub fn new(budget: usize) -> Self

Create a new streaming allocator with the given budget.

Source

pub fn set_eviction_callback<F>(&self, callback: F)
where F: Fn(StreamId) + Send + Sync + 'static,

Set a callback for when allocations are evicted.

Source

pub fn reserve(&self, size: usize, priority: StreamPriority) -> Option<StreamId>

Reserve memory for a streaming asset.

Returns None if the budget would be exceeded and eviction fails.

Source

pub fn reserve_tagged( &self, size: usize, priority: StreamPriority, tag: Option<&'static str>, ) -> Option<StreamId>

Reserve memory with a tag for categorization.

Source

pub fn begin_load(&self, id: StreamId) -> Option<*mut u8>

Get a pointer for writing data into a streaming allocation.

Returns None if the ID is invalid or the allocation is not in a writable state.

Source

pub fn report_progress(&self, id: StreamId, bytes_loaded: usize)

Report progress on loading.

Source

pub fn finish_load(&self, id: StreamId)

Mark a streaming allocation as fully loaded.

Source

pub fn access(&self, id: StreamId) -> Option<*const u8>

Access a ready allocation.

Updates the LRU timestamp.

Source

pub fn access_mut(&self, id: StreamId) -> Option<*mut u8>

Access a ready allocation mutably.

Source

pub fn free(&self, id: StreamId)

Free a streaming allocation.

Source

pub fn next_frame(&self)

Advance to the next frame (for LRU tracking).

Source

pub fn budget(&self) -> usize

Get the current memory budget.

Source

pub fn total_reserved(&self) -> usize

Get total reserved bytes.

Source

pub fn total_loaded(&self) -> usize

Get total loaded bytes.

Source

pub fn available(&self) -> usize

Get available budget.

Source

pub fn state(&self, id: StreamId) -> Option<StreamState>

Get the state of an allocation.

Source

pub fn stats(&self) -> StreamingStats

Get statistics about streaming allocations.

Trait Implementations§

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.