pub unsafe fn new_in_heap(ring_size: usize) -> Result<RingBuffer>{
        if ring_size & (ring_size - 1) != 0 {
            // We need pages to be a power of 2.
            return Err(InvalidRingSize(ring_size).into());
        }

        let temp_vec: Vec<u8> = vec![0; ring_size * 8 + 16];
        let mut boxed: SuperBox = SuperBox{ my_box: temp_vec.into_boxed_slice(), }; // Box<[u8]> is just like &[u8];

        let address = &mut boxed.my_box[0] as *mut u8;
        unsafe{
            *(address as *mut usize) = 0;
            *((address as *mut usize).offset(1)) = 0;
            *((address as *mut usize).offset(2)) = ring_size;
            *((address as *mut usize).offset(3)) = ring_size - 1;
        }

        Ok(RingBuffer {
            boxed,
            head: SuperUsize{ my_usize: (address as *mut usize) },
            tail: SuperUsize{ my_usize: (address as *mut usize).offset(1) }, 
            size: SuperUsize{ my_usize: (address as *mut usize).offset(2) },
            mask: SuperUsize{ my_usize: (address as *mut usize).offset(3) },
            vec: SuperVec{ my_vec: (address as *mut usize).offset(4) as (*mut (*mut MBuf)) },
        })
    }
/// Create a new wrapping ring buffer. The ring buffer size is specified in bytes and must be a power of 2. 
/// bytes is the number of bytes of RingBuffer::vec
/// we will require additional 16 bytes to store the meta-data for this ring.
Create a new wrapping ring buffer. The ring buffer size is specified in bytes and must be a power of 2.
bytes is the number of bytes of RingBuffer::vec
we will require additional 16 bytes to store the meta-data for this ring.
Create a new wrapping ring buffer . The ring buffer size is specified in bytes and must be a power of 2 . bytes is the number of bytes of RingBuffer :: vec we will require additional 16 bytes to store the meta - data for this ring .
pub unsafe fn new_in_heap(ring_size: usize) -> Result<RingBuffer>{
        if ring_size & (ring_size - 1) != 0 {
            // We need pages to be a power of 2.
            return Err(InvalidRingSize(ring_size).into());
        }
        let temp_vec: Vec<u8> = vec![0; ring_size * 8 + 16];
        let mut boxed: SuperBox = SuperBox{ my_box: temp_vec.into_boxed_slice(), }; // Box<[u8]> is just like &[u8];
        let address = &mut boxed.my_box[0] as *mut u8;
        unsafe{
            *(address as *mut usize) = 0;
            *((address as *mut usize).offset(1)) = 0;
            *((address as *mut usize).offset(2)) = ring_size;
            *((address as *mut usize).offset(3)) = ring_size - 1;
        }
        Ok(RingBuffer {
            boxed,
            head: SuperUsize{ my_usize: (address as *mut usize) },
            tail: SuperUsize{ my_usize: (address as *mut usize).offset(1) }, 
            size: SuperUsize{ my_usize: (address as *mut usize).offset(2) },
            mask: SuperUsize{ my_usize: (address as *mut usize).offset(3) },
            vec: SuperVec{ my_vec: (address as *mut usize).offset(4) as (*mut (*mut MBuf)) },
        })
    }
pub unsafe fn new_in_heap ( ring_size : usize ) -> Result < RingBuffer > { if ring_size & ( ring_size - 1 ) != 0 { // We need pages to be a power of 2. return Err ( InvalidRingSize ( ring_size ) . into ( ) ) ; } let temp_vec : Vec < u8 > = vec ! [ 0 ring_size 8 16 ] ; let mut boxed : SuperBox = SuperBox { my_box : temp_vec . into_boxed_slice ( ) , } ; // Box<[u8]> is just like &[u8]; let address = & mut boxed . my_box [ 0 ] as * mut u8 ; unsafe { * ( address as * mut usize ) = 0 ; * ( ( address as * mut usize ) . offset ( 1 ) ) = 0 ; * ( ( address as * mut usize ) . offset ( 2 ) ) = ring_size ; * ( ( address as * mut usize ) . offset ( 3 ) ) = ring_size - 1 ; } Ok ( RingBuffer { boxed , head : SuperUsize { my_usize : ( address as * mut usize ) } , tail : SuperUsize { my_usize : ( address as * mut usize ) . offset ( 1 ) } , size : SuperUsize { my_usize : ( address as * mut usize ) . offset ( 2 ) } , mask : SuperUsize { my_usize : ( address as * mut usize ) . offset ( 3 ) } , vec : SuperVec { my_vec : ( address as * mut usize ) . offset ( 4 ) as ( * mut ( * mut MBuf ) ) } , } ) }
Create a new wrapping ring buffer.
Create a new wrapping ring buffer .
ring_size
usize
ring_size
usize