Expand description
A simple garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread.
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).
This crate also contains optional triple buffer types for syncing
data (enable with the triple_buffer feature).
§Example
let value_1 = ArcGc::new(String::from("foo"));
// Same as `ArcGc` but for `!Sync` data.
let value_2 = OwnedGc::new(String::from("bar"));
// 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 `GlobalRtGc::collect()` periodically to deallocate
// any resources that were dropped on the realtime thread.
GlobalRtGc::collect();
std::thread::sleep(Duration::from_millis(15));
}You can also use a non-static collector with LocalRtGc (enabled in
the local_collector feature).
Structs§
- ArcGc
- A realtime-safe wrapper around
Arcthat when dropped, automatically has its contents collected and later deallocated on another non-realtime thread. - ArcGc
Input - The input (producer) end to a triple buffer that is used to send
ArcGcdata to a realtime thread. - ArcGc
Output - The output (consumer) end to a triple buffer that is used to send
ArcGcdata to a realtime thread. - Global
RtGc - A simple garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread.
- Local
RtGc - A simple garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread.
- Local
RtGc Handle - A handle to a
LocalRtGcgarbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread. - OwnedGc
- A realtime-safe
!Syncresource that when dropped, automatically has its contents collected and later deallocated on another non-realtime thread. - Owned
GcInput - The input (producer) end to a triple buffer that is used to send
OwnedGcdata to a realtime thread. - Owned
GcOutput - The output (consumer) end to a triple buffer that is used to send
OwnedGcdata to a realtime thread. - Owned
GcUnsized - A realtime-safe
!Syncresource that when dropped, automatically has its contents collected and later deallocated on another non-realtime thread.
Traits§
- Collector
- A trait which describes a garbage collector which collects resources dropped on a realtime thread and safely deallocates them on another thread.
- Strong
Count - A trait for type-erasing
Arc<T>types.
Functions§
- arc_
gc_ triple_ buffer - Create a new triple buffer that can be used to send
ArcGcdata to a realtime thread. - owned_
gc_ triple_ buffer - Create a new triple buffer that can be used to send
OwnedGcdata to a realtime thread.