Tries to free `capacity` bytes from this reservation if `capacity` does not exceed [`Self::size`]. Returns new reservation size, or error if shrinking capacity is more than allocated size.
(&self, capacity: usize)
| 419 | /// Returns new reservation size, |
| 420 | /// or error if shrinking capacity is more than allocated size. |
| 421 | pub fn try_shrink(&self, capacity: usize) -> Result<usize> { |
| 422 | let prev = self |
| 423 | .size |
| 424 | .fetch_update( |
| 425 | atomic::Ordering::Relaxed, |
| 426 | atomic::Ordering::Relaxed, |
| 427 | |prev| prev.checked_sub(capacity), |
| 428 | ) |
| 429 | .map_err(|prev| { |
| 430 | internal_datafusion_err!( |
| 431 | "Cannot free the capacity {capacity} out of allocated size {prev}" |
| 432 | ) |
| 433 | })?; |
| 434 | |
| 435 | self.registration.pool.shrink(self, capacity); |
| 436 | Ok(prev - capacity) |
| 437 | } |
| 438 | |
| 439 | /// Sets the size of this reservation to `capacity` |
| 440 | pub fn resize(&self, capacity: usize) { |