A Guide to Contiguous Data in Rust

Hi! I've written a draft of A Guide to Contiguous Data in Rust, an opinionated guide that tries to help programmers choose the best way to store contiguous data in Rust. I would love to hear if anyone has error corrections or other suggested improvements!

Under Allocation

Some solutions can be used with const , where the data will live in the data segment of the binary (I think??),

That is static.
const is for constant evaluation (reference)

1 Like

under smallvec

Whereas an array with type [T; 4] stores exactly 4 elements, a SmallVec of type SmallVec[T; 4] can store more than 4 elements, but only the first 4 elements will be stored on the stack.

That sounds like the first 4 elements would be on the stack and the remaining ones on the heap.
If the data fits the inline capacity, it is stored on the stack, otherwise it is stored on the heap.

1 Like

A honourable mention would be the ndarray crate for using n-dimensional arrays.

It is possible to do something like:

let data = vec![vec![property]];
let element = data[x][y];

but since the first vector is just a series of references to the inner vector, this is a big noob trap and can be quite slow if you have to do a lot of reads and writes.


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.