5 ms·
Now you are confusing everything. Delphi has three single byte string types since 1996: (ansi)string, shortstring and string[length], and the last two are mostl
by benibela 8y ago
Now you are confusing everything. Delphi has three single byte string types since 1996: (ansi)string, shortstring and string[length], and the last two are mostly there for backward compatibility.
>No awareness of encoding, so easy to break your text if you try to do anything other than pipe it through.
Which is good, when you have data with an unknown encoding. Unix file names for example, you can create a file that has an invalid utf-8 file name, and many tools that want to store the file name in a string with an encoding, just cannot access that file
>Single-byte length field, so your strings can't exceed 255 bytes, and you need a pointer indirection just to get the length of your string.
Ansistrings have a 32-bit length. I have not used Delphi on a 64 bit system, but in FreePascal they have a 64-bit length there.
shortstrings have a 255 max length, but since they are short they are mostly stored on the stack and you do not need any pointer indirection.
>Rc'd cow, so you never know whether your write is going to be free or incur a complete copy.
Shortstrings are not rc'd cow and are always copied. Since they are short and on the stack that copying is fast.
No write on long strings is free, since you can get a cache miss. And you only make a copy if some other function still has a reference string. How could that happen? The function should only keep the string around if it still needs the old value, and then it would need to make a copy anyways. No cow always leads to more copying.
>The null pointer is the empty string, you don't get to know whether you got no input or got an empty input.
If you want no input, you can use a pointer to a string.
>(Optionally) you're completely unable to implement generic string operations because the string type carries a length and the language gives no way to be generic over that.
Ansistrings do not have a length in the type, nor the basic shortstring. Nowadays you would define all string operations for ansistrings (=utf8strings).