pub struct LocalRtGc { /* private fields */ }Expand description
A simple garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread.
Unlike GlobalRtGc, this version does not
use global statics.
The performance characteristics of the ArcGc, OwnedGc, and
OwnedGcUnsized smart pointers are equivalant to Arc when
reading (but constructing them is a bit more expensive).
§Example
let mut collector = LocalRtGc::new();
let handle = collector.handle();
let value_1 = ArcGc::new_loc(String::from("foo"), &handle);
// Same as `ArcGc` but for `!Sync` data.
let value_2 = OwnedGc::new_loc(String::from("bar"), &handle);
// A simulated "realtime thread"
let rt_thread = std::thread::spawn(move || {
std::thread::sleep(Duration::from_millis(15));
// Dropping the values on the realtime thread is realtime-safe
// because the contents are automatically collected and
// deallocated on a separate non-realtime thread.
let _ = value_1;
let _ = value_2;
});
// A simulated update loop on the main thread
for _ in 0..4 {
// Call `collector.collect()` periodically to deallocate any
// resources that were dropped on the realtime thread.
collector.collect();
std::thread::sleep(Duration::from_millis(15));
}Implementations§
Source§impl LocalRtGc
impl LocalRtGc
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
pub fn handle(&self) -> LocalRtGcHandle
Sourcepub fn any_dropped(&self) -> bool
pub fn any_dropped(&self) -> bool
Returns true if any allocation has been dropped since the
collection cycle.
Sourcepub fn num_allocations(&self) -> usize
pub fn num_allocations(&self) -> usize
The total number of allocations currently active in this garbage collector.
Sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
The total number of active references to this garbage collector.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for LocalRtGc
impl RefUnwindSafe for LocalRtGc
impl Send for LocalRtGc
impl Sync for LocalRtGc
impl Unpin for LocalRtGc
impl UnwindSafe for LocalRtGc
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