pub struct BlobData { /* private fields */ }Expand description
Holds the raw payload sections of each blob file.
Indexed by PayloadLocator::blob_index. Blob 0’s payload section is loaded
eagerly by load_raw() – it carries the defs and the primary payloads and
is needed immediately. Overflow blobs (1, 2, …) start Unloaded and are
read from disk on demand the first time a locator references them, so a
large world does not pay the RAM (or I/O) cost of every overflow blob at
startup.
Systems call release(blob_index) after consuming a blob’s payloads (e.g.
after uploading SPIR-V to the GPU) so the memory is freed promptly.
Implementations§
Source§impl BlobData
impl BlobData
Sourcepub fn new(payload_sections: Vec<Option<Vec<u8>>>) -> BlobData
pub fn new(payload_sections: Vec<Option<Vec<u8>>>) -> BlobData
Build an in-memory store where every section is already resident. Used
by the cn debug path, which compiles payloads in memory with no blob
files, so there is nothing to lazily load. A None section is treated
as already released.
Sourcepub fn empty() -> BlobData
pub fn empty() -> BlobData
empty store for worlds with no compiled payloads (tests, runtime-only worlds)
Sourcepub fn disk_backed(&self) -> bool
pub fn disk_backed(&self) -> bool
true when the payloads were loaded from blob files on disk, so a streamed payload can be re-read from disk rather than kept in RAM
Sourcepub fn read(&mut self, locator: &PayloadLocator) -> Result<&[u8], CnResult>
pub fn read(&mut self, locator: &PayloadLocator) -> Result<&[u8], CnResult>
read the bytes for a given locator
An Unloaded overflow blob is read from its file on first access and
becomes Loaded. Errors if the locator is out of range, the blob was
released, or the on-demand load fails.
Sourcepub fn release(&mut self, blob_index: u32)
pub fn release(&mut self, blob_index: u32)
release a blob’s in-memory payload once all systems that need it have finished consuming it (e.g. after GPU upload)
subsequent read() calls for locators in this blob return an error
rather than reloading – the data is known to no longer be needed – so
only call this once you are sure no other system needs it
Sourcepub fn release_all_resident(&mut self) -> usize
pub fn release_all_resident(&mut self) -> usize
Release every payload section still resident, called once every system
has finished init. Systems read compiled payloads only during init and
cache what they keep (GPU uploads, decoded audio clips, streaming
sources that own their extracted bytes or re-read from disk), so nothing
consults BlobData again at runtime – the resident sections are dead
weight past World::start. Never-loaded overflow slots are left as they
are: they hold only a file path and were needed by no system. Returns the
number of bytes freed.
Trait Implementations§
Source§impl PayloadStore for BlobData
impl PayloadStore for BlobData
Source§fn read(&mut self, locator: &PayloadLocator) -> Result<&[u8], CnResult>
fn read(&mut self, locator: &PayloadLocator) -> Result<&[u8], CnResult>
&mut self because a disk-backed
store may load an overflow section lazily on first access. Errors when
the payload was released, the locator is out of range, or a lazy load
fails.Source§fn release(&mut self, blob_index: u32)
fn release(&mut self, blob_index: u32)
blob_index treats this as a no-op.Source§fn disk_backed(&self) -> bool
fn disk_backed(&self) -> bool
Source§fn release_all_resident(&mut self) -> usize
fn release_all_resident(&mut self) -> usize
World::start calls this after init: systems read compiled payloads
only while initing and cache what they keep, so nothing consults the
store again. A store with nothing resident frees nothing.Auto Trait Implementations§
impl Freeze for BlobData
impl RefUnwindSafe for BlobData
impl Send for BlobData
impl Sync for BlobData
impl Unpin for BlobData
impl UnsafeUnpin for BlobData
impl UnwindSafe for BlobData
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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