#struct array member size from previous struct member
1 messages · Page 1 of 1 (latest)
if you want a dynamically sized array, you could allocate it on the heap and use a slice as the type, or you could use std.BoundedArray (which stores an array of some fixed maximum capacity and lets you treat it as dynamic and growable up to that maximum)
and arraylist uses an allocator
it just stores a fixed size array in the struct itself
since you provide the capacity at comptime
like std.BoundedArray(100, u64) contains a [100]u64 field
yes
you can use readStruct with an ArrayList. Reader is not coupled to any concrete data structure.
you should use Writer and writeStruct, though. a Reader reads from reader to buffer. a Writer writes from buffer to writer.
if you wish to transfer bytes from a stream to a zig structure, you can use Writer and write from a stream to that structure.
in other words, you can make a Writer with an ArrayList context and then write from your buffers into that array list
Reader and Writer are in a sense put on top of a structure. a Reader reads from that structure into a slice. but you can only fill it up to its length. a Writer writes from a slice into that structure. So if that structure is an ArrayList, it can handle the reallocations for you.
you can't read off from the reader straight into an ArrayList