Struct vm_memory::volatile_memory::VolatileArrayRef [−][src]
pub struct VolatileArrayRef<'a, T, B = ()> { /* fields omitted */ }
Expand description
A memory location that supports volatile access to an array of elements of type T
.
Examples
let mut v = [5u32; 1]; let v_ref = unsafe { VolatileArrayRef::new(&mut v[0] as *mut u32 as *mut u8, v.len()) }; assert_eq!(v[0], 5); assert_eq!(v_ref.load(0), 5); v_ref.store(0, 500); assert_eq!(v[0], 500);
Implementations
Creates a VolatileArrayRef
to an array of elements of
type T
.
Safety
To use this safely, the caller must guarantee that the memory at addr
is big enough for
nelem
values of type T
and is available for the duration of the lifetime of the new
VolatileRef
. The caller must also guarantee that all other users of the given chunk of
memory are using volatile accesses.
Creates a VolatileArrayRef
to an array of elements of
type T
, using the provided bitmap
object for dirty page tracking.
Safety
To use this safely, the caller must guarantee that the memory at addr
is big enough for
nelem
values of type T
and is available for the duration of the lifetime of the new
VolatileRef
. The caller must also guarantee that all other users of the given chunk of
memory are using volatile accesses.
Returns true
if this array is empty.
Examples
let v_array = unsafe { VolatileArrayRef::<u32>::new(0 as *mut _, 0) }; assert!(v_array.is_empty());
Returns the size of T
.
Examples
let v_ref = unsafe { VolatileArrayRef::<u32>::new(0 as *mut _, 0) }; assert_eq!(v_ref.element_size(), size_of::<u32>() as usize);
Returns a pointer to the underlying memory. Mutable accesses performed using the resulting pointer are not automatically accounted for by the dirty bitmap tracking functionality.
Converts this to a VolatileSlice
with the same size and address.
Does a volatile read of the element at index
.
Copies as many elements of type T
as possible from this array to buf
.
Copies self.len()
or buf.len()
times the size of T
bytes, whichever is smaller,
to buf
. The copy happens from smallest to largest address in T
sized chunks
using volatile reads.
Examples
let mut v = [0u8; 32]; let v_ref = unsafe { VolatileArrayRef::new(&mut v[0] as *mut u8, v.len()) }; let mut buf = [5u8; 16]; v_ref.copy_to(&mut buf[..]); for &v in &buf[..] { assert_eq!(v, 0); }
Copies as many bytes as possible from this slice to the provided slice
.
The copies happen in an undefined order.
Examples
let mut v = [0u8; 32]; let v_ref = unsafe { VolatileArrayRef::<u8>::new(&mut v[0] as *mut u8, v.len()) }; let mut buf = [5u8; 16]; let v_ref2 = unsafe { VolatileArrayRef::<u8>::new(&mut buf[0] as *mut u8, buf.len()) }; v_ref.copy_to_volatile_slice(v_ref2.to_slice()); for &v in &buf[..] { assert_eq!(v, 0); }
Copies as many elements of type T
as possible from buf
to this slice.
Copies self.len()
or buf.len()
times the size of T
bytes, whichever is smaller,
to this slice’s memory. The copy happens from smallest to largest address in
T
sized chunks using volatile writes.
Examples
let mut v = [0u8; 32]; let v_ref = unsafe { VolatileArrayRef::<u8>::new(&mut v[0] as *mut u8, v.len()) }; let buf = [5u8; 64]; v_ref.copy_from(&buf[..]); for &val in &v[..] { assert_eq!(5u8, val); }
Trait Implementations
Performs the conversion.
Auto Trait Implementations
impl<'a, T, B> RefUnwindSafe for VolatileArrayRef<'a, T, B> where
B: RefUnwindSafe,
T: RefUnwindSafe,
impl<'a, T, B = ()> !Send for VolatileArrayRef<'a, T, B>
impl<'a, T, B = ()> !Sync for VolatileArrayRef<'a, T, B>
impl<'a, T, B> Unpin for VolatileArrayRef<'a, T, B> where
B: Unpin,
impl<'a, T, B> UnwindSafe for VolatileArrayRef<'a, T, B> where
B: UnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more