Expand description
Thread-local allocators.
Temp is for heap allocations that last a short time.
Local is for heap allocations that last a longer time ( but not longer than the thread ).
Temp and Local are not Send or Sync, so values allocated from them cannot be accssed by other threads.
Temp uses “bump” allocation, deallocate just decreases a count of outstanding allocations.
This means there is no minimum allocation internally.
Allocations larger than 64K bytes, or having more than 128 byte alignment, are routed to Global.
Local has an array of free lists, one for each size class 16,32,64…64K.
The minimum internal allocation (on a 64-bit system) is 16 bytes, which is also the maximum alignment.
Allocations larger than 64K bytes, or having more than 16 byte alignment, are routed to Global.
Example
use pstd::{Box,Vec,localalloc::Local};
let b = Box::new_in(98, Local::new());
assert!(*b == 98);
type TBox<T> = Box::<T,Temp>; // Temp allocated Box.
let b = TBox::auto(99); // Alternative to using new_in.
assert!(*b == 99);
type LVec<T> = Vec<T,Local>; // Locally allocated Vec.
let mut v = LVec::with_capacity_auto(4); // Pre-allocate space for 4 values.
v.push("Hello");
assert!(v.pop() == Some("Hello"));