Struct rarena_allocator::ArenaOptions
source · pub struct ArenaOptions { /* private fields */ }Expand description
Options for creating an ARENA
Implementations§
source§impl ArenaOptions
impl ArenaOptions
sourcepub const fn with_reserved(self, reserved: u32) -> Self
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);sourcepub const fn with_maximum_alignment(self, alignment: usize) -> Self
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);sourcepub const fn with_capacity(self, capacity: u32) -> Self
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);sourcepub const fn with_minimum_segment_size(self, minimum_segment_size: u32) -> Self
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);sourcepub const fn with_maximum_retries(self, maximum_retries: u8) -> Self
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);sourcepub const fn with_unify(self, unify: bool) -> Self
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);sourcepub const fn with_magic_version(self, magic_version: u16) -> Self
pub const fn with_magic_version(self, magic_version: u16) -> Self
sourcepub const fn with_freelist(self, freelist: Freelist) -> Self
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);sourcepub const fn reserved(&self) -> u32
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);sourcepub const fn maximum_alignment(&self) -> usize
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);sourcepub const fn capacity(&self) -> u32
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);sourcepub const fn minimum_segment_size(&self) -> u32
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);sourcepub const fn maximum_retries(&self) -> u8
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);sourcepub const fn unify(&self) -> bool
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);sourcepub const fn magic_version(&self) -> u16
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);Trait Implementations§
source§impl Clone for ArenaOptions
impl Clone for ArenaOptions
source§fn clone(&self) -> ArenaOptions
fn clone(&self) -> ArenaOptions
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for ArenaOptions
impl Debug for ArenaOptions
source§impl Default for ArenaOptions
impl Default for ArenaOptions
impl Copy for ArenaOptions
Auto Trait Implementations§
impl Freeze for ArenaOptions
impl RefUnwindSafe for ArenaOptions
impl Send for ArenaOptions
impl Sync for ArenaOptions
impl Unpin for ArenaOptions
impl UnwindSafe for ArenaOptions
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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