#![allow(dead_code)]
// #![feature(box_syntax)]
// use std::convert::TryInto;
// use std::sync::{Arc, Mutex};
// use std::mem::transmute;
// use bytes::{Bytes, BytesMut, Buf, BufMut};

pub struct MemoryManager {
    memory_pool: Box<[u8]>
}

pub type ByteLen = usize;

impl MemoryManager {

    pub fn alloc_u32(n: usize) -> Box<[u32]> {
        vec![0u32; n].into_boxed_slice()
    }
    pub fn alloc_u8(n: usize) -> Box<[u8]> {
        vec![0u8; n].into_boxed_slice()
    }

    pub fn new(pool_size: usize) -> MemoryManager {
        MemoryManager {
            memory_pool: MemoryManager::alloc_u8(pool_size)
        }
    }

    pub fn memory_pool_size(self) -> usize {
        self.memory_pool.len()
    }

    pub fn slice_mut(&mut self, start: ByteLen) -> Box<[u8]> {
        unsafe {
            Box::from_raw(&mut self.memory_pool[start..] as *mut _ as *mut [u8])
        }
    }

    pub fn set(&mut self, at: usize, val: u8) {
        self.memory_pool[at] = val;
    }
}
