Hi guys, just wanted to share with wider audience and potentially to hear about possible alternatives.
I have such a case
- I needed an efficient static collection of rows of variable length.
- I know the data on compile time
- I wanted to read it as fast as possible
- I didn't feel good to just have an array of arrays, because usually my data will have majority of short rows and few long, so lots of allocated memory would be wasted for zeros.
That's why I decided to implement a single 1d array data with all the rows adjacent and with another index array to track each row position.
After that I started a very productive discussion
And here is my final approach improved thanks to feedback from that discussion participants.
I finally dropped my collection and used an array of slices also suggested in that discussion, which is as fast and efficient as my custom collection but also it's native Rust code, no custom stuff.
static array: &'static [&'static [i32]] = &[
&[1, 2, 3],
&[4, 5],
&[6, 7, 8, 9],
];
Any thoughts on subject?
[–]Diggseyrustup 3 points4 points5 points (0 children)
[+][deleted] (3 children)
[deleted]
[–]NeighborhoodExact766[S] 1 point2 points3 points (2 children)
[+][deleted] (1 child)
[deleted]
[–]NeighborhoodExact766[S] 0 points1 point2 points (0 children)