Skip to content

Instantly share code, notes, and snippets.

@ezyang
Created December 10, 2013 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezyang/7902078 to your computer and use it in GitHub Desktop.
Save ezyang/7902078 to your computer and use it in GitHub Desktop.
pub fn new(n: nat) -> MBlock {
let ptr = unsafe { aligned_alloc_raw(MBLOCK_SIZE as size_t, (MBLOCK_SIZE * n) as size_t) };
assert!(!ptr::is_null(ptr));
let mb = MBlock{ptr: ptr};
// XXX should this really be here?
unsafe {
let mut block = mb.first_block_ptr();
let mut bd = mb.first_bdescr_ptr();
while (block <= mb.last_block_ptr()) {
(*bd).data.start = cast_ptr(block);
bd = bd.offset(1);
block = block.offset(BLOCK_SIZE as int);
}
}
mb
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment