pub struct GlobalMemoryPool { /* private fields */ }Expand description
Enhanced global memory pool with SciRS2 memory optimization
Implementations§
Source§impl GlobalMemoryPool
impl GlobalMemoryPool
Sourcepub fn create_large_tensor<T>(
&mut self,
shape: &[usize],
device: DeviceType,
) -> Result<Tensor<T>>
pub fn create_large_tensor<T>( &mut self, shape: &[usize], device: DeviceType, ) -> Result<Tensor<T>>
✅ SciRS2 Memory-Efficient Tensor Creation for Large Tensors
Sourcepub fn create_lazy_tensor<T>(
&mut self,
shape: &[usize],
device: DeviceType,
) -> Result<Tensor<T>>
pub fn create_lazy_tensor<T>( &mut self, shape: &[usize], device: DeviceType, ) -> Result<Tensor<T>>
✅ SciRS2 Lazy Tensor Creation - Defer allocation until needed
Sourcepub fn create_zero_copy_view<T>(
&self,
source: &Tensor<T>,
offset: usize,
shape: &[usize],
) -> Result<Tensor<T>>where
T: Clone + TensorElement,
pub fn create_zero_copy_view<T>(
&self,
source: &Tensor<T>,
offset: usize,
shape: &[usize],
) -> Result<Tensor<T>>where
T: Clone + TensorElement,
✅ SciRS2 Zero-Copy Operations for efficient tensor views
Sourcepub fn get_enhanced_stats(&self) -> PoolStatistics
pub fn get_enhanced_stats(&self) -> PoolStatistics
Get memory usage statistics enhanced with SciRS2 metrics
Sourcepub fn acquire_uninit<T: 'static>(&mut self, count: usize) -> ReusedBuffer<T>
pub fn acquire_uninit<T: 'static>(&mut self, count: usize) -> ReusedBuffer<T>
Acquire a truly-pooled, uninitialized buffer for count elements of type T
with natural alignment (align_of::<T>()).
This is the low-level method. Prefer the free function global_acquire_uninit.
The returned ReusedBuffer<T> holds the actual pooled allocation — no copy
is made. Callers must initialize all elements before reading them.
For custom alignment (e.g. 32-byte SIMD alignment), use
Self::acquire_uninit_aligned instead.
Sourcepub fn acquire_uninit_aligned<T: 'static>(
&mut self,
count: usize,
align: usize,
) -> ReusedBuffer<T>
pub fn acquire_uninit_aligned<T: 'static>( &mut self, count: usize, align: usize, ) -> ReusedBuffer<T>
Acquire a pooled uninitialized buffer with custom alignment.
Useful for SIMD-aligned buffers (32-byte for AVX2, 64-byte for AVX-512, etc.).
Buffers acquired with a given align go into their own bucket keyed by
(TypeId, SizeClass, align), so they never collide with naturally-aligned
allocations of the same type+size.
§Panics
- if
alignis not a power of two - if
align < std::mem::align_of::<T>()
Sourcepub fn allocate<T: TensorElement + Default + 'static>(
&mut self,
count: usize,
) -> Vec<T>
👎Deprecated: Use global_acquire_uninit instead for zero-copy buffer reuse
pub fn allocate<T: TensorElement + Default + 'static>( &mut self, count: usize, ) -> Vec<T>
Use global_acquire_uninit instead for zero-copy buffer reuse
Allocate memory for tensor elements.
Returns a zero-initialized Vec<T>.
§Deprecation
Use global_acquire_uninit for zero-copy buffer reuse.
Sourcepub fn find_size_class(&self, size_bytes: usize) -> usize
pub fn find_size_class(&self, size_bytes: usize) -> usize
Find appropriate size class for allocation
Sourcepub fn deallocate<T: 'static>(&mut self, data: Vec<T>)
pub fn deallocate<T: 'static>(&mut self, data: Vec<T>)
Deallocate memory by dropping it (legacy; buffer is not returned to pool).
The deallocate method previously attempted to store the allocation in the pool
using an unsafe Vec<u8> transmutation that could not reconstruct the correct
layout. Now the Vec is simply dropped. Use ReusedBuffer::release_to_pool for
true pool return.
Sourcepub fn get_statistics(&self) -> &PoolStatistics
pub fn get_statistics(&self) -> &PoolStatistics
Get basic statistics
Trait Implementations§
Source§impl Debug for GlobalMemoryPool
impl Debug for GlobalMemoryPool
Auto Trait Implementations§
impl !Freeze for GlobalMemoryPool
impl !RefUnwindSafe for GlobalMemoryPool
impl !Sync for GlobalMemoryPool
impl !UnwindSafe for GlobalMemoryPool
impl Send for GlobalMemoryPool
impl Unpin for GlobalMemoryPool
impl UnsafeUnpin for GlobalMemoryPool
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
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