[][src]Struct bumpalo_herd::Herd

pub struct Herd(_);

A group of Bump allocators.

This contains a bunch of Bump allocators. They can be borrowed into threads with get. Once the returned Member proxies get dropped, they return back in here. This means they can be used again, by more threads. But more importantly, the memory allocated from them is still valid.

The allocators are created on demand ‒ if no existing ones are cached inside, new one is created.

Implementations

impl Herd[src]

pub fn new() -> Self[src]

Creates a new Herd.

No allocators are created at that point, it is empty, but will be populated on use.

pub fn reset(&mut self)[src]

Deallocates all memory from all the allocators.

This is similar to Bump::reset from bumpalo, but works on all the allocators of this herd. Note that this takes &mut, they can't be in active use by any threads at this point.

Note that it is not possible to reset individual Bumps as the memory in there could belong to some other (previous) thread and the lifetime of allocated objects are not tied to them, only to the Herd.

pub fn get(&self) -> Member<'_>[src]

Borrows a member allocator from this herd.

As the Herd is Sync, it is possible to call this from the worker threads. The Member is a proxy around Bump, allowing to allocate objects with lifetime of the Herd (therefore, the allocated objects can live longer than the Member itself).

Performance note

This is not cheap and is not expected to happen often. It contains a mutex.

The expected usage pattern is that each worker thread (or similar entity) grabs one allocator once, at its start and uses it through its lifetime, not that it would call get on each allocation.

Trait Implementations

impl Default for Herd[src]

Auto Trait Implementations

impl RefUnwindSafe for Herd

impl Send for Herd

impl Sync for Herd

impl Unpin for Herd

impl UnwindSafe for Herd

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.