use std::{
alloc::{GlobalAlloc, Layout, System},
ptr::NonNull,
};
use crate::generated::fixed_size_constants::{BLOCK_ALIGN, BLOCK_SIZE};
use super::super::Arena;
const ALLOC_LAYOUT: Layout = match Layout::from_size_align(BLOCK_SIZE, BLOCK_ALIGN) {
Ok(layout) => layout,
Err(_) => unreachable!(),
};
const _: () = assert!(ALLOC_LAYOUT.size() > 0);
impl<const MIN_ALIGN: usize> Arena<MIN_ALIGN> {
pub fn new_fixed_size() -> Option<Self> {
let alloc_ptr = unsafe { System.alloc(ALLOC_LAYOUT) };
let alloc_ptr = NonNull::new(alloc_ptr)?;
debug_assert!(alloc_ptr.addr().get().is_multiple_of(BLOCK_ALIGN));
let arena = unsafe { Self::from_raw_parts(alloc_ptr, BLOCK_SIZE, alloc_ptr, ALLOC_LAYOUT) };
Some(arena)
}
}