std :: alloc::slab
Struct std::SlabAllocator
struct SlabAllocator {
&heap unsigned char base;
int owned;
?&SlabLink_ free_head;
unsigned long obj_size;
unsigned long cap;
unsigned long used;
int has_tags;
}Fields
heap-backed backing buffer
1 if SlabAllocator::new allocated base (destroy() frees it)
head of the embedded free list (walked inside unsafe)
slot size: the requested size rounded up to a multiple of 8
max number of objects
currently allocated count
1 if each slot has an extra 8-byte double-free-detection tag ahead of it (SlabAllocator::new, where this allocator sized+owns 'base' itself, so growing the per-slot stride is safe) — 0 if not (SlabAllocator::over, where 'base' is caller-provided and sized to the documented obj_size*count contract, which adding a tag would silently overrun).
Methods
static struct SlabAllocator over([]unsigned char buffer, unsigned long obj_size)source · definitionA slab over a caller-provided buffer. Slots are obj_size rounded up to a multiple of 8 (at least 8, to hold the free-list link) and start 8-byte aligned, so 'cap' can come out below buffer.len / obj_size when that rounding doesn't fit. No double-free detection (see has_tags) — the buffer size contract can't grow to fit a tag.
A heap-backed slab of count objects (double-free-detecting).
Allocate one object (all obj_size bytes of it) for size bytes
aligned to align. null if the slab is full, size > obj_size, or
align is above max_align() or not a power of two (0 is taken as 1).
Return an object to the pool (null: no-op). Aborts with a diagnostic on double-free (SlabAllocator::new-created allocators only — see has_tags above).
Free every slot at once (slots handed out before become invalid).
Return the number of free slots remaining.
The largest alignment alloc honours: the largest power of two dividing obj_size, at most 8 (given an 8-aligned buffer: always for SlabAllocator::new).
Free the backing buffer (only valid for heap-backed allocators from SlabAllocator::new).
= drop()