pub struct AnalyticsContext { /* private fields */ }Expand description
Context for analytics operations with grouped buffer lifecycle.
All buffers allocated through this context are released together when the context is dropped. This is useful for analytics operations that need multiple temporary buffers.
§Thread Safety
AnalyticsContext is Send but not Sync. Each context should be
used from a single thread. For parallel analytics, create a separate
context per thread.
Implementations§
Source§impl AnalyticsContext
impl AnalyticsContext
Sourcepub fn with_capacity(
name: impl Into<String>,
expected_allocations: usize,
) -> Self
pub fn with_capacity( name: impl Into<String>, expected_allocations: usize, ) -> Self
Create a context with pre-allocated capacity.
Reserves space for the expected number of allocations to avoid reallocations of the internal vectors.
Sourcepub fn allocate(&mut self, size: usize) -> AllocationHandle
pub fn allocate(&mut self, size: usize) -> AllocationHandle
Sourcepub fn allocate_typed<T: Copy + Default + 'static>(
&mut self,
count: usize,
) -> AllocationHandle
pub fn allocate_typed<T: Copy + Default + 'static>( &mut self, count: usize, ) -> AllocationHandle
Sourcepub fn get(&self, handle: AllocationHandle) -> &[u8] ⓘ
pub fn get(&self, handle: AllocationHandle) -> &[u8] ⓘ
Sourcepub fn get_mut(&mut self, handle: AllocationHandle) -> &mut [u8] ⓘ
pub fn get_mut(&mut self, handle: AllocationHandle) -> &mut [u8] ⓘ
Sourcepub fn get_typed<T: Copy>(&self, handle: AllocationHandle) -> &[T]
pub fn get_typed<T: Copy>(&self, handle: AllocationHandle) -> &[T]
Sourcepub fn get_typed_mut<T: Copy>(&mut self, handle: AllocationHandle) -> &mut [T]
pub fn get_typed_mut<T: Copy>(&mut self, handle: AllocationHandle) -> &mut [T]
Sourcepub fn try_get(&self, handle: AllocationHandle) -> Option<&[u8]>
pub fn try_get(&self, handle: AllocationHandle) -> Option<&[u8]>
Try to get a reference to an allocated buffer.
Returns None if the handle is invalid.
Sourcepub fn try_get_mut(&mut self, handle: AllocationHandle) -> Option<&mut [u8]>
pub fn try_get_mut(&mut self, handle: AllocationHandle) -> Option<&mut [u8]>
Try to get a mutable reference to an allocated buffer.
Returns None if the handle is invalid.
Sourcepub fn allocation_size(&self, handle: AllocationHandle) -> usize
pub fn allocation_size(&self, handle: AllocationHandle) -> usize
Sourcepub fn allocation_count(&self) -> usize
pub fn allocation_count(&self) -> usize
Get the number of allocations in this context.
Sourcepub fn stats(&self) -> &ContextStats
pub fn stats(&self) -> &ContextStats
Get statistics for this context.
Sourcepub fn release_all(&mut self)
pub fn release_all(&mut self)
Release all allocations and reset the context.
After calling this, all handles become invalid.
Sourcepub fn sub_context(&self, name: impl Into<String>) -> Self
pub fn sub_context(&self, name: impl Into<String>) -> Self
Create a sub-context for a nested operation.
The sub-context shares no allocations with the parent.