Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ShortString in Unicode Version

In old Delphi versions (ANSI string), ShortStrings:

var Str: String[30];

Could be used to reduce memory cost and still had ANSI Encoding.

In current Unicode Versions, Is ShortString like above, aliased to some Unicode encoded version?
Does the advantage of this practice still exists to reduce memory cost?

like image 925
EProgrammerNotFound Avatar asked Jul 04 '26 15:07

EProgrammerNotFound


1 Answers

A Delphi short string always uses the ANSI encoding, even in modern Unicode aware Delphi versions. They are considered a legacy data type and so Embarcadero elected not to make changes when it introduced Unicode.

For what it is worth, using a short string did not necessarily reduce memory costs. It would only do so if your strings were all close to the same length. If your strings had any significant variation in length, then using dynamic (a.k.a. long) strings would result in lower memory overhead.

I don't think that short strings were ever better than dynamic strings. They exist simply because they pre-date dynamic strings. Had dynamic strings been invented first, short strings would not exist. Indeed they do not exist in the new mobile compilers. In other words, just use dynamic strings.

like image 114
David Heffernan Avatar answered Jul 07 '26 05:07

David Heffernan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!