Skip to main content

PrivateCollector

Struct PrivateCollector 

Source
pub struct PrivateCollector { /* private fields */ }
Expand description

Private garbage collector to limit the lifetime of allocated memory chunks.

When the PrivateCollector is dropped, it performs an aggressive reclamation; it deallocates all remaining memory chunks that it has collected in its lifetime without ensuring that there are no active Ptr or RawPtr pointing to any of the memory chunks.

§Safety

Using PrivateCollector for types that do not implement Send is unsafe, as their instances may be dropped on an arbitrary thread. See collect_owned and collect_shared for more safety notes.

Implementations§

Source§

impl PrivateCollector

Source

pub const fn new() -> Self

Creates a new PrivateCollector.

§Examples
use sdd::PrivateCollector;

let private_collector = PrivateCollector::new();
Source

pub unsafe fn collect_owned<T>(&self, owned: Owned<T>, guard: &Guard)

Collects the memory owned by the supplied Owned.

§Safety

This method is unsafe because it manually manages the lifetime of the underlying memory. The caller must ensure that the PrivateCollector is not dropped while any Ptr or RawPtr still point to the memory held by the Owned.

Additionally, T must implement Send because its instances may be dropped on an arbitrary thread: for example, when the PrivateCollector is moved across threads or shared among multiple threads. The Send constraint is intentionally not enforced at compile time to allow for more flexibility.

§Examples
use sdd::{Guard, Owned, PrivateCollector};

let private_collector = PrivateCollector::new();
let owned = Owned::new(10);

unsafe { private_collector.collect_owned(owned, &Guard::new()); }
Source

pub unsafe fn collect_shared<T>(&self, shared: Shared<T>, guard: &Guard) -> bool

Collects the supplied Shared.

Returns true if the last reference was dropped and the memory was successfully collected.

§Safety

This method is unsafe because it manually manages the lifetime of the underlying memory. The caller must ensure that the PrivateCollector is not dropped while any Ptr or RawPtr still point to the memory held by the Shared.

Additionally, T must implement Send because its instances may be dropped on an arbitrary thread: for example, when the PrivateCollector is moved across threads or shared among multiple threads. The Send constraint is intentionally not enforced at compile time to allow for more flexibility.

§Examples
use sdd::{Guard, PrivateCollector, Shared};

let private_collector = PrivateCollector::new();
let shared = Shared::new(10);

let collected = unsafe { private_collector.collect_shared(shared, &Guard::new()) };
assert!(collected);

Trait Implementations§

Source§

impl Default for PrivateCollector

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Drop for PrivateCollector

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.