Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

scoped allocator and customizable reference implementation? #11

Open
hh9527 opened this issue Feb 21, 2017 · 0 comments
Open

scoped allocator and customizable reference implementation? #11

hh9527 opened this issue Feb 21, 2017 · 0 comments

Comments

@hh9527
Copy link

hh9527 commented Feb 21, 2017

Is it possible to support Allocator type parameter and support customized deref?

pub trait Allocatior {
  type RefId;
  unsafe fn alloc(&self, size: usize, align: usize) -> (Self::RefId, *mut u8);
  unsafe fn dealloc(&self, id: Self::RefId);
  unsafe fn deref(&self, id: Self::RefId) -> *mut u8;
}

struct MyRelocatableAllocator {
  heap: Arc<Mutex<Vec<u8>>>, // big contiguous buffer from mmap'd memory which shared between process 
}

impl Allocator for MyRelocatableAllocator {
  // ...
}

fn test(allocator: MyRelocatableAllocator) {
  let map = HamtMap::with_allocator(allocator)
    .plus(1u32, "one")
    .plus(2u32, "two")
    .plus(3u32, "three");
  // do something with immutable map
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant