pub struct NDArrayPool { /* private fields */ }Expand description
NDArray factory with free-list reuse and memory tracking.
Mimics C++ ADCore’s NDArrayPool: on alloc, checks the free list for a buffer with sufficient capacity. On release, returns the buffer to the free list for future reuse. The free list is sorted by capacity (descending) and excess entries are dropped when max_memory is exceeded.
Implementations§
Source§impl NDArrayPool
impl NDArrayPool
pub fn new(max_memory: usize) -> Self
Sourcepub fn alloc(
&self,
dims: Vec<NDDimension>,
data_type: NDDataType,
) -> ADResult<NDArray>
pub fn alloc( &self, dims: Vec<NDDimension>, data_type: NDDataType, ) -> ADResult<NDArray>
Allocate an NDArray. Tries to reuse a free-list entry with sufficient capacity.
Sourcepub fn alloc_copy(&self, source: &NDArray) -> ADResult<NDArray>
pub fn alloc_copy(&self, source: &NDArray) -> ADResult<NDArray>
Allocate a copy of an existing NDArray (new unique_id, data cloned).
Sourcepub fn empty_free_list(&self)
pub fn empty_free_list(&self)
Clear all entries from the free list.
pub fn allocated_bytes(&self) -> u64
pub fn num_alloc_buffers(&self) -> u32
pub fn num_free_buffers(&self) -> u32
pub fn max_memory(&self) -> usize
Sourcepub fn alloc_handle(
pool: &Arc<Self>,
dims: Vec<NDDimension>,
data_type: NDDataType,
) -> ADResult<NDArrayHandle>
pub fn alloc_handle( pool: &Arc<Self>, dims: Vec<NDDimension>, data_type: NDDataType, ) -> ADResult<NDArrayHandle>
Allocate an NDArray wrapped in a pool-aware handle. On final drop, the array is returned to this pool’s free list.
Auto Trait Implementations§
impl !Freeze for NDArrayPool
impl !RefUnwindSafe for NDArrayPool
impl Send for NDArrayPool
impl Sync for NDArrayPool
impl Unpin for NDArrayPool
impl UnsafeUnpin for NDArrayPool
impl UnwindSafe for NDArrayPool
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
Mutably borrows from an owned value. Read more