3 ms·
Different flavors for different use-cases. There was even $-terminated ones prevalent on DOS which got it from CP/M which got it from DEC OS/8. Pascal-style st
by hi-v-rocknroll 3y ago
Different flavors for different use-cases. There was even $-terminated ones prevalent on DOS which got it from CP/M which got it from DEC OS/8.
Pascal-style strings (length + data or length + pointer to data) have the nice properties of O(1) size inquiry, simpler bounds checking, and easier to represent strings that contain embedded NULs. A downside is though you have to pick an unsigned integer width of power of 2, usually 0 to 3. Another upside is (length + pointer to data) immutable substrings (with longer lifetimes that the parent string) are very cheap because they just point to wherever in the start and specify how much of the parent string with the length. There was a language IIRC that implemented a more complicated Pascal-style strings perhaps for COW or reference counting of the underlying allocation.