// offset is measured in "count of T's plus alignment padding", not in bytes.
offset is measured in "count of T's plus alignment padding", not in bytes.
offset is measured in " count of T ' s plus alignment padding " not in bytes .
pub fn write_array<T: Copy>(&mut self, data: &[T], offset: Option<usize>)
                                -> Result<(), Error>
    {
        let ptr = match self.ptr {
            None => return Err(Error::MemoryNotHostWritable),
            Some(rpu) => rpu
        };
        let stride = _stride(::std::mem::size_of::<T>(),
                             self.element_alignment as usize);
        let offset = offset.unwrap_or(0_usize);
        assert!(stride * (offset + data.len()) <= self.size as usize);
        // If we don't have gaps, we can use rust slices
        if stride == ::std::mem::size_of::<T>() {
            unsafe {
                let dest: &mut [T] = ::std::slice::from_raw_parts_mut(
                    ptr.offset((offset * stride) as isize) as *mut T,
                    data.len()
                );
                dest.copy_from_slice(data);
            }
        } else {
            // Note: we cannot use copy_from_slice() because slices in rust don't
            // have alignment pdding between the elements.
            for i in offset..offset + data.len() {
                unsafe {
                    let p = ptr.offset((i * stride) as isize) as *mut T;
                    *p = data[i];
                }
            }
        }
        // mark dirty
        self.dirty.store(true, Ordering::Relaxed);
        Ok(())
    }
pub fn write_array < T : Copy > ( & mut self , data : & [ T ] , offset : Option < usize > ) -> Result < ( ) , Error > { let ptr = match self . ptr { None => return Err ( Error :: MemoryNotHostWritable ) , Some ( rpu ) => rpu } ; let stride = _stride ( :: std :: mem :: size_of :: < T > ( ) , self . element_alignment as usize ) ; let offset = offset . unwrap_or ( 0_usize ) ; assert ! ( stride ( offset data len ( ) ) self size as usize ) ; // If we don't have gaps, we can use rust slices if stride == :: std :: mem :: size_of :: < T > ( ) { unsafe { let dest : & mut [ T ] = :: std :: slice :: from_raw_parts_mut ( ptr . offset ( ( offset * stride ) as isize ) as * mut T , data . len ( ) ) ; dest . copy_from_slice ( data ) ; } } else { // Note: we cannot use copy_from_slice() because slices in rust don't // have alignment pdding between the elements. for i in offset .. offset + data . len ( ) { unsafe { let p = ptr . offset ( ( i * stride ) as isize ) as * mut T ; * p = data [ i ] ; } } } // mark dirty self . dirty . store ( true , Ordering :: Relaxed ) ; Ok ( ( ) ) }
offset is measured in "count of T's plus alignment padding", not in bytes.
offset is measured in " count of T ' s plus alignment padding " not in bytes .
&mut self
data
&[T]
offset
Option<usize>