by WaitWaitWha · 10mo ago · 0 comments
This is how Borland Turbo Pascal stored strings as far back as the first version in mid-80s.
Length followed by the string.
This is different from Pascal strings.
Pascal strings are: { length, pointer }
In these strings:
For short strings it's storing:
{ length, string value}
for longer strings, it's storing {length, prefix, class, pointer }The historical P-strings are just a pointer, with the length at the head of the buffer. Hence length-prefixed strings, and their limitation to 255 bytes (only one byte was reserved for the length, you can still see this in the most base string of freepascal: https://www.freepascal.org/docs-html/ref/refsu9.html).
{length, pointer}
or {length, capacity, pointer}
is struct / record strings, and what pretty much every modern language does (possibly with optimisations e.g. SSO23 is basically a p-string when inline, but can move out of line into a full record string).