3 ms·
>Eg length-prefix strings would avoid the slow strlens for concatenation. But this would be suboptimal in other ways. Besides taking more RAM, it would get in
by xamuel 12y ago
>Eg length-prefix strings would avoid the slow strlens for concatenation.
But this would be suboptimal in other ways. Besides taking more RAM, it would get in the way of useful tricks like "temporarily shorten string by setting a particular byte in it to \0", or even more useful, "obtain right-terminal substring by simply increasing pointer value".
Different string implementations are more efficient in different scenarios. I love how C gives us standard libraries for a particular string implementation (NULL-terminated) but at the same time allows the flexibility to use whatever implementation we like, by not abstracting all the details out of our control.