Struct rb_sys::tracking_allocator::TrackingAllocator
source · pub struct TrackingAllocator;
Expand description
A simple wrapper over std::alloc::System
which reports memory usage to
the Ruby GC. This gives the GC a more accurate picture of the process’
memory usage so it can make better decisions about when to run.
Implementations§
source§impl TrackingAllocator
impl TrackingAllocator
sourcepub const fn new() -> Self
pub const fn new() -> Self
Create a new TrackingAllocator
.
sourcepub const fn default() -> Self
pub const fn default() -> Self
Create a new TrackingAllocator
with default values.
sourcepub fn adjust_memory_usage(delta: isize) -> isize
pub fn adjust_memory_usage(delta: isize) -> isize
Adjust the memory usage reported to the Ruby GC by delta
. Useful for
tracking allocations invisible to the Rust allocator, such as mmap
or
direct malloc
calls.
§Example
use rb_sys::TrackingAllocator;
// Allocate 1024 bytes of memory using `mmap` or `malloc`...
TrackingAllocator::adjust_memory_usage(1024);
// ...and then after the memory is freed, adjust the memory usage again.
TrackingAllocator::adjust_memory_usage(-1024);
Trait Implementations§
source§impl Debug for TrackingAllocator
impl Debug for TrackingAllocator
source§impl GlobalAlloc for TrackingAllocator
impl GlobalAlloc for TrackingAllocator
source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocate memory as described by the given
layout
. Read moresource§unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8
Behaves like
alloc
, but also ensures that the contents
are set to zero before being returned. Read moreAuto Trait Implementations§
impl Freeze for TrackingAllocator
impl RefUnwindSafe for TrackingAllocator
impl Send for TrackingAllocator
impl Sync for TrackingAllocator
impl Unpin for TrackingAllocator
impl UnwindSafe for TrackingAllocator
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