3 ms·
> I'm not up-to-date - does pascal have a 64-bit string type? Seems like an easy fix is a single type of string with dynamic size depending on the first byte,
by cornholio 8y ago
> I'm not up-to-date - does pascal have a 64-bit string type?
Seems like an easy fix is a single type of string with dynamic size depending on the first byte, like UTF-8:
0bbbbbbb : 1 byte header for a string up to 127 bytes long
10bbbbbb + hh : 2 byte header for a string up to 16384 bytes long
110bbbbb + hhhhhh: 4 byte header for a string up to 512 MB long
1110bbbb + hhhhhhhhhhhhhh: 8 byte header for a string up 1.15 EB long
... etc. (so as not to repeat the mistakes of Pascal, who knows how long will 1.15 EB be enough for everybody)
You would optimize the functions for the fast path with a single bit test for short <128 byte strings, and end up with a sane, safe string until the end of time. With minimal memory impact and much faster than testing for nul terminators, strlen() all over the place etc.
- samatman 8y agoThis is the intuitively right answer, and has always been my favorite. It's so puzzling that this is a data structure I can't recall ever seeing in the wild.