Closed
Description
Hi, I noticed that len
is arranged after xs
pub struct ArrayVec<T, const CAP: usize> {
// the `len` first elements of the array are initialized
xs: [MaybeUninit<T>; CAP],
len: LenUint,
}
In C's world, it's a convention to move length before an array, like
#[repr(C)]
pub struct ArrayVec<T, const CAP: usize> {
len: LenUint,
// the `len` first elements of the array are initialized
xs: [MaybeUninit<T>; CAP]
}
This provides a few nice features:
- better locality. First, read the length, then read the element one by one. This should be trivial though
- Easier to implement tail arrays if were to put on the heap
- https://github.com/antirez/sds Simply Dynamic String uses a similar layout
Metadata
Metadata
Assignees
Labels
No labels