pub struct SlabRemote<T, B: Allocator + FixedRange> { /* private fields */ }Expand description
Remote deallocation handle. Send + Sync — freely cloneable across
threads. Implements Deallocator only; cannot allocate.
§API-misuse compile-failures (pinned)
SlabRemote<T, B> is Send + Sync only when T: Send (and
B: Send). Instantiating with a non-Send T (e.g. Rc<u64>)
and then trying to ship the remote across threads is rejected at
compile time:
// FAILS TO COMPILE: SlabRemote's `Send` bound requires `T: Send`,
// so `SlabRemote<Rc<u64>, _>` is not `Send` and cannot satisfy
// `assert_send`.
use std::rc::Rc;
use forge_alloc::InlineBacked;
use forge_alloc::SlabRemote;
fn assert_send<T: Send>() {}
assert_send::<SlabRemote<Rc<u64>, InlineBacked<512>>>();Implementations§
Source§impl<T, B: Allocator + FixedRange> SlabRemote<T, B>
impl<T, B: Allocator + FixedRange> SlabRemote<T, B>
Sourcepub unsafe fn try_deallocate(
&self,
ptr: NonNull<u8>,
layout: NonZeroLayout,
) -> Result<(), NonNull<u8>>
pub unsafe fn try_deallocate( &self, ptr: NonNull<u8>, layout: NonZeroLayout, ) -> Result<(), NonNull<u8>>
Non-spinning remote deallocate. Returns Err(ptr) if the queue is
full or the owner has been dropped (queue is closed); caller
retains ownership and must handle the pointer (typically by
dropping it once the whole slab tears down).
§Safety
ptr must have been allocated from the corresponding SlabOwner.
On Err, the pointer is still owned by the caller.
Trait Implementations§
Source§impl<T: Clone, B: Clone + Allocator + FixedRange> Clone for SlabRemote<T, B>
impl<T: Clone, B: Clone + Allocator + FixedRange> Clone for SlabRemote<T, B>
Source§fn clone(&self) -> SlabRemote<T, B>
fn clone(&self) -> SlabRemote<T, B>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T, B: Allocator + FixedRange> Deallocator for SlabRemote<T, B>
impl<T, B: Allocator + FixedRange> Deallocator for SlabRemote<T, B>
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: NonZeroLayout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: NonZeroLayout)
Spins until the queue accepts the deallocation, except when
the owner has been dropped — in that case the queue will never
drain again, so we return immediately. The slot remains
marked-live in the slab until the last SlabRemote clone
releases the shared Arc<SlabInner> (at which point the slab
itself drops and the backing region is fully reclaimed). Any
T: Drop whose destructor was already run by the caller before
deallocate is not affected — the destructor ran on schedule;
only the freelist entry for the slot is forfeited.
Latency-sensitive callers should use try_deallocate
and handle the Err(ptr) overflow / closed-queue explicitly.