pub struct Arena<T, const BITARRAY_LEN: usize, const LEN: usize> { /* private fields */ }
Expand description
  • LEN - Number of elements stored per bucket. Must be less than or equal to u32::MAX, divisible by usize::BITS and it must not be 0.

  • BITARRAY_LEN - Number bits in the bitmap per bucket. Must be equal to LEN / usize::BITS.

    For best performance, try to set this to number of CPUs that are going to access Arena concurrently.

Arena stores the elements in buckets to ensure that the address for elements are stable while improving efficiency.

Every bucket is of size LEN.

The larger LEN is, the more compact the Arena will be, however it might also waste space if it is unused.

And, allocating a large chunk of memory takes more time.

Arena internally stores the array of buckets as a triomphe::ThinArc and use ArcSwapAny to grow the array atomically, without blocking any reader.

Examples

If you provides Arena with invalid LEM or BITARRAY_LEN, then your code will panic at runtime:

use concurrent_arena::*;
let arena = Arena::<u32, 1, 100>::new();

To make it a compile time failure, you need to call max_buckets:

use concurrent_arena::*;
const MAX_BUCKETS: u32 = Arena::<u32, 1, 100>::max_buckets();

Implementations

Maximum buckets Arena can have.

Would preallocate 2 buckets.

Return Ok(arc) on success, or Err((value, len)) where value is the input param value and len is the length of the Arena at the time of insertion.

This function is lock-free.

Try to reserve min(new_len, Self::max_buckets()) buckets.

This function is technically lock-free.

Reserve min(new_len, Self::max_buckets()) buckets.

Insert one value.

If there isn’t enough buckets, then try to reserve one bucket and restart the operation.

May enter busy loop if the slot is not fully initialized.

This function is lock free.

May enter busy loop if the slot is not fully initialized.

This function is lock free.

Return number of buckets allocated.

This function is lock free.

This function is lock free.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.