Last active
August 29, 2015 14:11
-
-
Save rrichardson/908a09c8e0bb6d6110e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #![feature(globs)] | |
| #![feature(phase)] | |
| extern crate iobuf; | |
| extern crate alloc; | |
| #[phase(plugin, link)] | |
| extern crate log; | |
| #[phase(plugin)] | |
| extern crate lazy_static; | |
| extern crate mio_processor; | |
| use iobuf::{RWIobuf, AROIobuf, Allocator}; | |
| use mio::{Buf}; | |
| use alloc::heap as a; | |
| use std::sync::Arc; | |
| static BUF_SIZE : uint = 1600; | |
| struct MyAllocator; | |
| impl Allocator for MyAllocator { | |
| fn allocate(&self, size: uint, align: uint) -> *mut u8 { | |
| unsafe { a::allocate(size, align) } | |
| } | |
| fn deallocate(&self, ptr: *mut u8, len: uint, align: uint) { | |
| unsafe { a::deallocate(ptr, len, align) } | |
| } | |
| } | |
| lazy_static! { | |
| static ref MYALLOC: Arc<Box<Allocator>> = { | |
| Arc::new( (box MyAllocator) as Box<Allocator>) | |
| }; | |
| } | |
| #[test] | |
| fn main() { | |
| use mio_processor::*; | |
| let buf_creator = |capacity: uint| -> RWIobuf<'static> { | |
| RWIobuf::new_with_allocator(capacity, MYALLOC.clone()) | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment