pub struct Arc<T: Poolable> { /* private fields */ }Expand description
A poolable drop-in replacement for std::sync::Arc.
This Arc pools its allocations, reducing overhead when frequently creating and destroying Arc instances. When the last strong reference is dropped, the allocation is returned to the pool instead of being freed.
§Example
use poolshark::global::arc::Arc;
use poolshark::global::RawPool;
let pool: RawPool<Arc<String>> = RawPool::new(1024, 1);
let arc1 = Arc::new(&pool, "hello".to_string());
let arc2 = arc1.clone(); // Reference counting works normally
drop(arc1);
drop(arc2); // Returns to pool when last reference drops§Differences from std::sync::Arc
- Requires a pool to be created from
- Returns to pool when dropped (if strong_count == 1)
- Slightly larger memory footprint (stores pool pointer)
Implementations§
Source§impl<T: Poolable> Arc<T>
impl<T: Poolable> Arc<T>
Sourcepub fn new(pool: &RawPool<Self>, v: T) -> Self
pub fn new(pool: &RawPool<Self>, v: T) -> Self
Allocate a new arc from the specified pool.
Returns an arc containing v.
Sourcepub fn get_mut(&mut self) -> Option<&mut T>
pub fn get_mut(&mut self) -> Option<&mut T>
Get a mutable reference to the inner value if the Arc is unique.
Returns None if the Arc is not unique (strong_count > 1).
Sourcepub fn strong_count(&self) -> usize
pub fn strong_count(&self) -> usize
Return the strong reference count of the arc.
Trait Implementations§
impl<T: Poolable + Eq> Eq for Arc<T>
Source§impl<T: Poolable + Ord> Ord for Arc<T>
impl<T: Poolable + Ord> Ord for Arc<T>
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: Poolable + PartialOrd> PartialOrd for Arc<T>
impl<T: Poolable + PartialOrd> PartialOrd for Arc<T>
Source§impl<T: Poolable> RawPoolable for Arc<T>
impl<T: Poolable> RawPoolable for Arc<T>
Source§fn empty(pool: WeakPool<Self>) -> Self
fn empty(pool: WeakPool<Self>) -> Self
allocate a new empty object and set it’s pool pointer to
poolSource§fn reset(&mut self)
fn reset(&mut self)
empty the collection and reset it to its default state so it
can be put back in the pool
Source§fn really_drop(self)
fn really_drop(self)
Actually drop the inner object, don’t put it back in the pool,
make sure you do not call both this method and the drop
implementation that puts the object back in the pool!
Auto Trait Implementations§
impl<T> Freeze for Arc<T>
impl<T> RefUnwindSafe for Arc<T>where
T: RefUnwindSafe,
impl<T> Send for Arc<T>
impl<T> Sync for Arc<T>
impl<T> Unpin for Arc<T>
impl<T> UnsafeUnpin for Arc<T>
impl<T> UnwindSafe for Arc<T>where
T: RefUnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.