Struct rb_sys::tracking_allocator::ManuallyTracked
source · pub struct ManuallyTracked<T> { /* private fields */ }Expand description
A guard which adjusts the memory usage reported to the Ruby GC by delta.
This allows you to track resources which are invisible to the Rust
allocator, such as items that are known to internally use mmap or direct
malloc in their implementation.
Internally, it uses an Arc<AtomicIsize> to track the memory usage delta,
and is safe to clone when T is Clone.
Example
use rb_sys::tracking_allocator::ManuallyTracked;
type SomethingThatUsedMmap = ();
// Will tell the Ruby GC that 1024 bytes were allocated.
let item = ManuallyTracked::new(SomethingThatUsedMmap, 1024);
// Will tell the Ruby GC that 1024 bytes were freed.
std::mem::drop(item);Implementations§
source§impl<T> ManuallyTracked<T>
impl<T> ManuallyTracked<T>
sourcepub fn wrap(item: T, memsize: usize) -> Self
pub fn wrap(item: T, memsize: usize) -> Self
Create a new ManuallyTracked<T>, and immediately report that memsize
bytes were allocated.
sourcepub fn increase_memory_usage(&self, memsize: usize)
pub fn increase_memory_usage(&self, memsize: usize)
Increase the memory usage reported to the Ruby GC by memsize bytes.
sourcepub fn decrease_memory_usage(&self, memsize: usize)
pub fn decrease_memory_usage(&self, memsize: usize)
Decrease the memory usage reported to the Ruby GC by memsize bytes.
sourcepub fn memsize_delta(&self) -> isize
pub fn memsize_delta(&self) -> isize
Get the current memory usage delta.
Trait Implementations§
source§impl<T: Clone> Clone for ManuallyTracked<T>
impl<T: Clone> Clone for ManuallyTracked<T>
source§impl<T: Debug> Debug for ManuallyTracked<T>
impl<T: Debug> Debug for ManuallyTracked<T>
Auto Trait Implementations§
impl<T> RefUnwindSafe for ManuallyTracked<T>where T: RefUnwindSafe,
impl<T> Send for ManuallyTracked<T>where T: Send,
impl<T> Sync for ManuallyTracked<T>where T: Sync,
impl<T> Unpin for ManuallyTracked<T>where T: Unpin,
impl<T> UnwindSafe for ManuallyTracked<T>where T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more