2 ms·
Because you can have extremely long strings without worrying about overflowing a fixed-size length prefix.
by derleth 13y ago
Because you can have extremely long strings without worrying about overflowing a fixed-size length prefix.
- dbaupp 13y agoA computer has a finite address space (e.g. 2^32 bytes on x86, 2^48 on x86-64), and always has a fixed size data type large enough to address it all; an in-memory string cannot possibly be usefully larger than this so using this finite-size type as the length-prefix is perfect & optimal. C-strings are useful in extremely constrained environments when the extra few bytes of the length prefix vs the trailing \0 byte is too much to pay, but are essentially just a security risk in any other situation.