Column Vec
colvec provides a derive macro which generates a Vec-like data structure. Compared to Vec<Example>, ExampleColVec has a transposed row / column layout. This means you can take a slice across an entire column of a single struct field. ColVec has the same struct size (size_of::<Vec<T>>() = 24 bytes) and growth factor (2) as Vec, and uses a single contiguous allocation.
Tradeoffs
- ColVec can be smaller than Vec when the Struct has padding, since no padding is needed in the transposed layout [^1].
- ColVec can be faster to iterate than Vec when only accessing a single struct field column because the unused data in the other fields do not occupy the cache line, and thus it has reduced cache eviction.
[^1]: To ensure proper alignment, the capacity is rounded up to a multiple of the item alignment.
Example
use ColVec;
let mut cols=new;
cols.push;
cols.push;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;