Question about Storables and memory cells

I need to know which values can be defined as Storables. From my understanding, a Storable is something that can be stored in a single memory cell, but as my teacher told me, the size of a cell depends on the language, but I've read things that don't specify that. I've done some tests printing memory adresses but it hasn't solved my question and I've searched everywhere but don't seem to find the answer.

i32 is probably Storable, but is a Tuple/Array/Vec a Storable? Based on my tests I'd get something like:

x is in memory here: 0x665fcff750
y is in memory here: 0x665fcff758

X and Y are Structs that consist of two i16 values, as I can see, because each one have two 16-bit values, they'd end up using 8 bytes each (4 per value). But, are they using multiple cells? even if they do, can they be considered Storable? are Cells in Rust somehow dynamic?

If there's a way to prove it myself or somewhere I can check it, it'd be great.

“Storable” and “memory cell” aren’t standard or commonly-used terminology, as far as I know, so it’s hard to answer this precisely without seeing the exact definitions your teacher is using.

If a memory cell means the smallest addressable unit of memory, then in Rust that is one byte (eight bits). The types that can be stored in a single byte include u8, i8, bool, and any custom types with size 1.

1 Like

"Storables: Values that can be stored in a memory cell and can't be updated selectively (atomic)" (roughly translated).

And as an example he added:

"In Pascal: Primitive values, sets, pointers."

Maybe this can help, but if not, i'll work with what you told me.

Tuples, arrays, and structs can be updated selectively: You can write to one field without accessing the others (except in the trivial cases with only one or zero fields—not counting fields of size zero). It sounds like this means they are not “storables.”

The only types that truly cannot be updated selectively are types that are a single byte wide. Even an i32 can be updated selectively in unsafe Rust, by obtaining a pointer to part of its memory location:

let mut x = 0i32;
unsafe {
    let y: *mut [u8; 4] = &mut x as *mut i32 as *mut [u8; 4];
    (*y)[3] = 0xff;
println!("{:x}", x);

However, you could argue that this type of mutation is only possible by casting away the original type, so it doesn’t count as updating a value of that type.


Just what I needed. Thank you so much!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.