ROADMAP v0.2.0 - Memory budget enforcement for large queries (see ROADMAP.md §1)
(&self, bytes: usize)
| 105 | /// ``` |
| 106 | #[allow(dead_code)] // ROADMAP v0.2.0 - Memory budget enforcement for large queries (see ROADMAP.md §1) |
| 107 | pub fn allocate(&self, bytes: usize) -> Result<(), ExecutionError> { |
| 108 | let current = self.allocated.fetch_add(bytes, Ordering::SeqCst); |
| 109 | let new_total = current + bytes; |
| 110 | |
| 111 | // Update peak if necessary |
| 112 | self.peak.fetch_max(new_total, Ordering::SeqCst); |
| 113 | |
| 114 | // Check if we exceeded the limit |
| 115 | if new_total > self.limit { |
| 116 | // Rollback allocation |
| 117 | self.allocated.fetch_sub(bytes, Ordering::SeqCst); |
| 118 | |
| 119 | return Err(ExecutionError::MemoryLimitExceeded { |
| 120 | limit: self.limit, |
| 121 | requested: new_total, |
| 122 | }); |
| 123 | } |
| 124 | |
| 125 | Ok(()) |
| 126 | } |
| 127 | |
| 128 | /// Try to allocate memory, returning false if budget exceeded |
| 129 | /// |
no outgoing calls