I have a large fixed-size array of variable-sized arrays of u32
. Most of the second dimension arrays will be empty (i.e. the first array will be sparsely populated). I think Vec
is the most suitable type for both dimensions (Vec<Vec<u32>>
). Because my first array might be quite large, I want to find the most space-efficient way to represent this.
I see two options:
I could use a
Vec<Option<Vec<u32>>>
. I'm guessing that asOption
is a tagged union, this would result each cell beingsizeof(Vec<u32>)
rounded up to the next word boundary for the tag.I could directly use
Vec::with_capacity(0)
for all cells. Does an emptyVec
allocate zero heap until it's used?
Which is the most space-efficient method?