Struct rarena_allocator::ArenaOptions

source ·
pub struct ArenaOptions { /* private fields */ }
Expand description

Options for creating an ARENA

Implementations§

source§

impl ArenaOptions

source

pub const fn new() -> Self

Create an options for creating an ARENA with default values.

source

pub const fn with_reserved(self, reserved: u32) -> Self

Set the reserved of the ARENA.

The reserved is used to configure the start position of the ARENA. This is useful when you want to add some bytes before the ARENA, e.g. when using the memory map file backed ARENA, you can set the reserved to the size to 8 to store a 8 bytes checksum.

The default reserved is 0.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_reserved(8);
source

pub const fn with_maximum_alignment(self, alignment: usize) -> Self

Set the maximum alignment of the ARENA.

If you are trying to allocate a T which requires a larger alignment than this value, then will lead to read_unaligned, which is undefined behavior on some platforms.

The alignment must be a power of 2. The default maximum alignment is 8.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_maximum_alignment(16);
source

pub const fn with_capacity(self, capacity: u32) -> Self

Set the capacity of the ARENA. If the ARENA is backed by a memory map and the original file size is less than the capacity, then the file will be resized to the capacity.

The capacity must be greater than the minimum capacity of the ARENA.

The default capacity is 1KB.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_capacity(2048);
source

pub const fn with_minimum_segment_size(self, minimum_segment_size: u32) -> Self

Set the minimum segment size of the ARENA.

This value controls the size of the holes.

The default minimum segment size is 48 bytes.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_minimum_segment_size(64);
source

pub const fn with_maximum_retries(self, maximum_retries: u8) -> Self

Set the maximum retries of the ARENA.

This value controls how many times the ARENA will retry to allocate from slow path.

The default maximum retries is 5.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_maximum_retries(10);
source

pub const fn with_unify(self, unify: bool) -> Self

Set if use the unify memory layout of the ARENA.

File backed ARENA has different memory layout with other kind backed ARENA, set this value to true will unify the memory layout of the ARENA, which means all kinds of backed ARENA will have the same memory layout.

This value will be ignored if the ARENA is backed by a file backed memory map.

The default value is false.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_unify(true);
source

pub const fn with_magic_version(self, magic_version: u16) -> Self

Set the external version of the ARENA, this is used by the application using Arena to ensure that it doesn’t open the Arena with incompatible data format.

The default value is 0.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_magic_version(1);
source

pub const fn with_freelist(self, freelist: Freelist) -> Self

Set the freelist configuration for the ARENA. The default freelist is Freelist::Optimistic.

§Example
use rarena_allocator::{ArenaOptions, Freelist};

let opts = ArenaOptions::new().with_freelist(Freelist::Pessimistic);
source

pub const fn reserved(&self) -> u32

Get the reserved of the ARENA.

The reserved is used to configure the start position of the ARENA. This is useful when you want to add some bytes before the ARENA, e.g. when using the memory map file backed ARENA, you can set the reserved to the size to 8 to store a 8 bytes checksum.

The default reserved is 0.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_reserved(8);

assert_eq!(opts.reserved(), 8);
source

pub const fn maximum_alignment(&self) -> usize

Get the maximum alignment of the ARENA.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_maximum_alignment(16);

assert_eq!(opts.maximum_alignment(), 16);
source

pub const fn capacity(&self) -> u32

Get the capacity of the ARENA.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_capacity(2048);

assert_eq!(opts.capacity(), 2048);
source

pub const fn minimum_segment_size(&self) -> u32

Get the minimum segment size of the ARENA.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_minimum_segment_size(64);

assert_eq!(opts.minimum_segment_size(), 64);
source

pub const fn maximum_retries(&self) -> u8

Get the maximum retries of the ARENA. This value controls how many times the ARENA will retry to allocate from slow path.

The default maximum retries is 5.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_maximum_retries(10);

assert_eq!(opts.maximum_retries(), 10);
source

pub const fn unify(&self) -> bool

Get if use the unify memory layout of the ARENA.

File backed ARENA has different memory layout with other kind backed ARENA, set this value to true will unify the memory layout of the ARENA, which means all kinds of backed ARENA will have the same memory layout.

This value will be ignored if the ARENA is backed by a file backed memory map.

The default value is false.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_unify(true);

assert_eq!(opts.unify(), true);
source

pub const fn magic_version(&self) -> u16

Get the external version of the ARENA, this is used by the application using Arena to ensure that it doesn’t open the Arena with incompatible data format.

The default value is 0.

§Example
use rarena_allocator::ArenaOptions;

let opts = ArenaOptions::new().with_magic_version(1);

assert_eq!(opts.magic_version(), 1);
source

pub const fn freelist(&self) -> Freelist

Get the freelist configuration for the ARENA.

§Example
use rarena_allocator::{ArenaOptions, Freelist};

let opts = ArenaOptions::new().with_freelist(Freelist::Pessimistic);

assert_eq!(opts.freelist(), Freelist::Pessimistic);

Trait Implementations§

source§

impl Clone for ArenaOptions

source§

fn clone(&self) -> ArenaOptions

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for ArenaOptions

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for ArenaOptions

source§

fn default() -> Self

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

impl Copy for ArenaOptions

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more