pub unsafe trait BlinkAllocator: Allocator {
    // Required method
    fn reset(&mut self);
}
Expand description

Extension trait for Allocator that defines blink allocator API. Blink-allocators are allocators with cheap allocation and potentially no-op deallocation. Blink-allocator can reuse deallocated memory, but not required to. Typically deallocation is either no-op or processed only if deallocating the very last allocated memory block. The reset method deallocates all memory allocated from this instance at once.

Additional guarantees are provided that

  • Allocator::shrink will always succeed and never move memory when ptr is already aligned to new_layout.align().

Safety

Draws most requirements from Allocator super-trait. The reset method may invalidate currently allocated memory if allocator is not cloneable.

Required Methods§

source

fn reset(&mut self)

Resets allocator potentially invalidating all allocations made from this instance. This is no-op if allocator is Clone (typically shared reference to blink-allocator).

Safety

Caller must guarantee that all allocations made from this instance won’t be used after this call. The potential invalid memory access will happen through raw pointer and requires unsafe.

This method requires mutable borrow of the blink-allocator and so cannot be called while collection types reference it. So it is safe to use reference to blink allocator as allocator type for, say, Vec and later then call reset safely. The Vec would have to be dropped (or forgotten) before calling reset due to mutable borrow.

Implementations on Foreign Types§

source§

impl<A> BlinkAllocator for &Awhere A: BlinkAllocator,

source§

fn reset(&mut self)

source§

impl<'a, A> BlinkAllocator for &'a mut Awhere &'a mut A: Allocator, A: BlinkAllocator,

source§

fn reset(&mut self)

Implementors§