Skip to main content

Segment

Struct Segment 

Source
pub struct Segment {
    pub next: *mut Segment,
    pub owner: usize,
    pub foreign: AtomicPtr<u8>,
    pub foreign_bytes: AtomicUsize,
    pub foreign_live: AtomicUsize,
    pub spans: [SpanMeta; 64],
    /* private fields */
}
Expand description

The header at the base of every segment.

Fields§

§next: *mut Segment

Intrusive list of a heap’s segments — an allocator cannot use a Vec to track its own memory without recursing into itself.

§owner: usize

The shard that owns every span here. Foreign frees find their way home through this.

§foreign: AtomicPtr<u8>

Slots freed by a thread other than the owner, as a lock-free stack of slot addresses. See [push_foreign] for why this is push-only.

§foreign_bytes: AtomicUsize

Slot bytes parked on foreign, so the accounting can price the list without walking it. Bytes rather than a count: one list carries slots of several classes, so a count cannot be converted back.

AtomicUsize rather than AtomicU64 because 32-bit targets (Cortex-M among them) have no 64-bit atomic, and a pending foreign-free list cannot exceed the address space anyway.

§foreign_live: AtomicUsize

Of those, the bytes callers actually asked for.

The owner’s live/rounding counters still include everything on this list, because the thread that freed it cannot touch another thread’s counters. Snapshots move the amount across so it is counted once — see Heap::snapshot.

§spans: [SpanMeta; 64]

Per-span bookkeeping, indexed by span number. Index 0 describes the header span itself and is never assigned a class.

Implementations§

Source§

impl Segment

Source

pub unsafe fn init(base: NonNull<u8>, owner: usize) -> NonNull<Segment>

Initialise a freshly mapped segment in place.

§Safety

base must be a live, writable, 4 MiB-aligned mapping of SEGMENT_BYTES bytes that nothing else references.

Source

pub fn span_base(&self, index: usize) -> *mut u8

Base address of span index within this segment.

Source

pub fn is_valid(&self) -> bool

Check the header is one of ours. A false result means a pointer reached dealloc that this allocator never handed out.

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 = !

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.