I have a file format that I am parsing into a Zig structure. 99% of the time, in practice, a particular portion of the file would always have n
size, and for this, I can parsed this into an array of n
size.
But there is no restriction preventing the n
to actually be n + x
.
So I am looking for an approach that always parses the first n
without needing to allocating, but if it encounters a file that has that portion set to n + x
, then allocation kicks in to allocate the extra size required.
I am thinking I can have a struct that has both the array and an uninitialized ArrayList, and manually have the logic to only allocate the ArrayList when the n
is filled up.
Before doing something like this, I was wondering if there is something in the std that combines working with known size with the option to also allocate on demand when needed.