4 ms·
This isn't the same thing though. A flex array includes the data inline in the struct so allocating a struct with a flex array at the end requires just one call
by eklitzke 4y ago
This isn't the same thing though. A flex array includes the data inline in the struct so allocating a struct with a flex array at the end requires just one call to malloc and avoids a pointer indirection when indexing into the array.
- WalterBright 4y agoBounds checked arrays do not have an extra indirection.
- dzaima 4y agoThe question here is about what happens when such an array is part of a heap-allocated struct where there's already a layer of indirection. As far as I can tell, the [..] proposal would effectively be equivalent to pointer & length fields as far as data layout goes, but there are no pointers stored for a flexible array member, as getting the address of an element is just adding an offset to the struct's address, hence it has less indirection.