Newer
Older
vengine / engine-core / src / ephemeral_pool.rs
Maple Nebel Maple Nebel 9 days ago 866 bytes things
use std::{alloc::Allocator, io};

use memmap2::MmapMut;
use thiserror::Error;

#[derive(Error, Debug)]
enum Error {
    #[error(transparent)]
    Io(#[from] io::Error),
}

type Result<T, E = Error> = std::result::Result<T, E>;

struct EphemralPoolAllocator {
    raw_pool: memmap2::MmapRaw,
}

struct EphemralPoolAllocatorUnit {
    dealloc_callback: Box<dyn FnOnce()>,
}

unsafe impl Allocator for EphemralPoolAllocatorUnit {
    fn allocate(
        &self,
        _layout: std::alloc::Layout,
    ) -> Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError> {
        todo!()
    }

    unsafe fn deallocate(&self, _ptr: std::ptr::NonNull<u8>, _layout: std::alloc::Layout) {
        todo!()
    }
}

impl EphemralPoolAllocator {
    fn new(size: usize) -> Result<Self> {
        Ok(Self {
            raw_pool: MmapMut::map_anon(size)?.into(),
        })
    }
}