3 ms·
> but you'll be incompatible with any code dealing with native C-strings Not entirely, see https://github.com/antirez/sds https://github.com/antirez/sds Basic
by paavoova 8y ago
> but you'll be incompatible with any code dealing with native C-strings
Not entirely, see https://github.com/antirez/sds https://github.com/antirez/sds
Basically, you have a header storing length, etc, but still null terminate, so library functions like strlen are none the wiser.
- the_duke 8y agoNim (the programming language) implements strings this way, AFAIK, with the same reason: to be easily compatible with the C ecosystem.
- saagarjha 8y agoYou lose the ability to pass create zero-cost slices, though. C++11 actually implements strings like this, but iterators allow you to pass in parts of the string as necessary.