Splits off `capacity` bytes from this [`MemoryReservation`] into a new [`MemoryReservation`] with the same [`MemoryConsumer`]. This can be useful to free part of this reservation with RAAI style dropping # Panics Panics if `capacity` exceeds [`Self::size`]
(&self, capacity: usize)
| 485 | /// |
| 486 | /// Panics if `capacity` exceeds [`Self::size`] |
| 487 | pub fn split(&self, capacity: usize) -> MemoryReservation { |
| 488 | self.size |
| 489 | .fetch_update( |
| 490 | atomic::Ordering::Relaxed, |
| 491 | atomic::Ordering::Relaxed, |
| 492 | |prev| prev.checked_sub(capacity), |
| 493 | ) |
| 494 | .unwrap(); |
| 495 | Self { |
| 496 | size: atomic::AtomicUsize::new(capacity), |
| 497 | registration: Arc::clone(&self.registration), |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /// Returns a new empty [`MemoryReservation`] with the same [`MemoryConsumer`] |
| 502 | pub fn new_empty(&self) -> Self { |