pub struct Memory { /* private fields */ }Expand description
Sparse, BCT-backed guest memory.
Implementations§
Source§impl Memory
impl Memory
Sourcepub fn pages_allocated(&self) -> usize
pub fn pages_allocated(&self) -> usize
How many pages are currently allocated. For tests and diagnostics.
Sourcepub fn is_aligned(addr: Word) -> bool
pub fn is_aligned(addr: Word) -> bool
True when addr is word-aligned. Equivalent to testing whether the low
trit is zero. Applies at every width, since everything aligns to the
word (D-14).
Sourcepub fn read_tryte(&self, addr: Word) -> Result<Tryte, MemoryError>
pub fn read_tryte(&self, addr: Word) -> Result<Tryte, MemoryError>
Reads one tryte. Errors if it was never written.
Sourcepub fn write_tryte(
&mut self,
addr: Word,
value: Tryte,
) -> Result<(), MemoryError>
pub fn write_tryte( &mut self, addr: Word, value: Tryte, ) -> Result<(), MemoryError>
Writes one tryte, allocating its page if needed.
Sourcepub fn is_initialised(&self, addr: Word) -> bool
pub fn is_initialised(&self, addr: Word) -> bool
True when this address holds a value that was actually written.
Sourcepub fn read_word(&self, addr: Word) -> Result<Word, MemoryError>
pub fn read_word(&self, addr: Word) -> Result<Word, MemoryError>
Reads a word: three trytes, least significant first.
Requires word alignment. The tryte at addr holds trits 0..9, the next
holds 9..18, and the last holds 18..27, so the weights are 3^0, 3^9 and
3^18.
Sourcepub fn write_word(&mut self, addr: Word, value: Word) -> Result<(), MemoryError>
pub fn write_word(&mut self, addr: Word, value: Word) -> Result<(), MemoryError>
Writes a word: three trytes, least significant first.
Sourcepub fn read_double(&self, addr: Word) -> Result<DoubleWord, MemoryError>
pub fn read_double(&self, addr: Word) -> Result<DoubleWord, MemoryError>
Reads a double word: six trytes, least significant first.
Aligned to the word rather than to its own six trytes. Six-tryte
alignment would require testing addr mod 6 == 0, which in base 3 means
checking that the low trit is zero and the digit sum is even, a 27-trit
reduction rather than a single trit test (D-14).
Sourcepub fn write_double(
&mut self,
addr: Word,
value: DoubleWord,
) -> Result<(), MemoryError>
pub fn write_double( &mut self, addr: Word, value: DoubleWord, ) -> Result<(), MemoryError>
Writes a double word: six trytes, least significant first.
Trait Implementations§
Source§impl Addressable for Memory
impl Addressable for Memory
Source§fn read_tryte(&mut self, addr: Word) -> Result<Tryte, MemoryError>
fn read_tryte(&mut self, addr: Word) -> Result<Tryte, MemoryError>
Source§fn write_tryte(&mut self, addr: Word, value: Tryte) -> Result<(), MemoryError>
fn write_tryte(&mut self, addr: Word, value: Tryte) -> Result<(), MemoryError>
Source§fn read_word(&mut self, addr: Word) -> Result<Word, MemoryError>
fn read_word(&mut self, addr: Word) -> Result<Word, MemoryError>
Source§fn write_word(&mut self, addr: Word, value: Word) -> Result<(), MemoryError>
fn write_word(&mut self, addr: Word, value: Word) -> Result<(), MemoryError>
Source§fn is_privileged(&self, _addr: Word) -> bool
fn is_privileged(&self, _addr: Word) -> bool
addr should require supervisor privilege. Read more