EProgrammerNotFound
EProgrammerNotFound

Reputation: 2471

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?

Upvotes: 3

Views: 725

Answers (1)

David Heffernan
David Heffernan

Reputation: 613572

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.

Upvotes: 5

Related Questions