Skip to main content

ruvector_core/
memory.rs

1//! Memory management utilities for ruvector-core
2//!
3//! This module provides memory-efficient data structures and utilities
4//! for vector storage operations.
5
6/// Memory pool for vector allocations.
7#[derive(Debug, Default)]
8pub struct MemoryPool {
9    /// Total allocated bytes.
10    allocated: usize,
11    /// Maximum allocation limit.
12    limit: Option<usize>,
13}
14
15impl MemoryPool {
16    /// Create a new memory pool.
17    pub fn new() -> Self {
18        Self::default()
19    }
20
21    /// Create a memory pool with a limit.
22    pub fn with_limit(limit: usize) -> Self {
23        Self {
24            allocated: 0,
25            limit: Some(limit),
26        }
27    }
28
29    /// Get currently allocated bytes.
30    pub fn allocated(&self) -> usize {
31        self.allocated
32    }
33
34    /// Get the allocation limit, if any.
35    pub fn limit(&self) -> Option<usize> {
36        self.limit
37    }
38}