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 number of elements in the array.

Examples

assert_eq!(v_array.len(), 1);

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.

Borrows the inner BitmapSlice.

Converts this to a VolatileSlice with the same size and address.

Does a volatile read of the element at index.

Does a volatile read of the element at index.

Does a volatile write 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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.