pub mod bump_allocator;
pub mod pointer_offset;
pub mod pool_allocator;
use core::{alloc::Layout, fmt::Debug, ptr::NonNull};
use iceoryx2_bb_elementary::allocation_strategy::AllocationStrategy;
pub use iceoryx2_bb_elementary_traits::allocator::{AllocationError, AllocationGrowError};
use iceoryx2_bb_elementary_traits::{
allocator::{Allocate, ContentPlacement, Deallocate, Grow},
zero_copy_send::ZeroCopySend,
};
pub use pointer_offset::*;
pub trait ShmAllocatorConfig: Copy + Default + Debug + Send {}
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub enum ShmAllocatorInitError {
MaxSupportedMemoryAlignmentInsufficient,
AllocationFailed,
}
impl core::fmt::Display for ShmAllocatorInitError {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
write!(f, "ShmAllocatorInitError::{self:?}")
}
}
impl core::error::Error for ShmAllocatorInitError {}
pub struct SharedMemorySetupHint<Config: ShmAllocatorConfig> {
pub payload_size: usize,
pub config: Config,
}
pub trait InitializedShmAllocator<'shm_allocator>:
Allocate<PointerOffset> + Deallocate<PointerOffset> + Grow<PointerOffset>
{
}
pub trait ShmAllocator: Debug + Send + Sync + 'static + ZeroCopySend {
type Configuration: ShmAllocatorConfig;
type Initialized<'shm_allocator>: InitializedShmAllocator<'shm_allocator>;
unsafe fn assume_init<'shm_allocator>(
&'shm_allocator self,
) -> Self::Initialized<'shm_allocator>;
fn resize_hint(
&self,
layout: Layout,
strategy: AllocationStrategy,
) -> SharedMemorySetupHint<Self::Configuration>;
fn initial_setup_hint(
max_chunk_layout: Layout,
max_number_of_chunks: usize,
) -> SharedMemorySetupHint<Self::Configuration>;
fn management_size(memory_size: usize, config: &Self::Configuration) -> usize;
unsafe fn new_uninit(
max_supported_alignment_by_memory: usize,
managed_memory: NonNull<[u8]>,
config: &Self::Configuration,
) -> Self;
unsafe fn init<Allocator: Allocate<NonNull<u8>>>(
&mut self,
mgmt_allocator: &Allocator,
) -> Result<(), ShmAllocatorInitError>;
fn unique_id() -> u8;
fn max_alignment(&self) -> usize;
fn relative_start_address(&self) -> usize;
}