Skip to content

Instantly share code, notes, and snippets.

@rrichardson
Last active August 29, 2015 14:11
Show Gist options
  • Select an option

  • Save rrichardson/908a09c8e0bb6d6110e5 to your computer and use it in GitHub Desktop.

Select an option

Save rrichardson/908a09c8e0bb6d6110e5 to your computer and use it in GitHub Desktop.
#![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