3 ms·
Length-embedded strings are little better than the 0-terminated ones. You cannot take a substring without copying. The "fat pointer" approach has been used in
by WalterBright 17y ago
Length-embedded strings are little better than the 0-terminated ones. You cannot take a substring without copying.
The "fat pointer" approach has been used in D for nearly 10 years now, and has proven itself to be very effective.
- InclinedPlane 17y agoYou cannot take a substring without copying. That's not a bug, it's a feature. Indeed, immutable strings should almost always be the default choice due to security concerns alone. C is optimized for the rare case, modern languages with immutable strings (like C#) are optimized for the common case, this is how it should be.
- bmm6o 17y agoI think you missed the point. Even with immutable strings, some representations will allow you to take a substring without copying data and some will not. Length-prefixed strings do not.