2 ms·
Debating the size of the size field is a folly: It's a struct with one char pointer, and a length field. For alignment / padding reasons, the length field with
by kzrdude 11y ago
Debating the size of the size field is a folly: It's a struct with one char pointer, and a length field. For alignment / padding reasons, the length field with use the size of a pointer anyway, so `size_t` is entirely appropriate (and never too small).
- gpderetta 11y agoA relatively common implementation of strings (as compared to slices) is to store the length before the char array. The length field can be encoded with a variable size encoding. The string itself is just a single pointer. If you have a real garbage collector of course using the same representation for strings and slices (two pointers or pointer+len) is appropriate.