MCPcopy Create free account
hub / github.com/apache/datafusion / try_shrink

Method try_shrink

datafusion/execution/src/memory_pool/mod.rs:421–437  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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) {

Callers 2

try_resizeMethod · 0.80
test_try_shrinkFunction · 0.80

Calls 1

shrinkMethod · 0.45

Tested by 1

test_try_shrinkFunction · 0.64