2 ms·
Yeah, you are right - I missed out the capacity part. Why is the parent pointing out Vec as being “opposed to a raw pointer, a length and a capacity”?
by heavenlyblue 7y ago
Yeah, you are right - I missed out the capacity part. Why is the parent pointing out Vec as being “opposed to a raw pointer, a length and a capacity”?
- steveklabnik 7y agoI believe that they mean you can’t mess it up; a slice is much nicer than two separate things. There’s no way to get them out of sync, etc.
- jstimpfle 7y agoI was pointing out vector objects (as opposed to rawpointers) mainly because I'm not aware of any other practical way to enable automated bounds checking. Apart from that I actually find it more appealing and "correct" to have a separate length value. As soon as there are multiple parallel arrays the vector approach will have redundant length information, so from an aesthetical point from of view I prefer not to glue the length to the vector/array. But yeah, with a separate length there is more manual work for simple tasks, so it's easier to mess up.
- pjmlp 7y agoBy being part of the same data structure and managed by the compiler there is no way to get out of sync, due to copy-paste or mismatch when several arrays are being used together.