> On Jul 4, 2023, at 10:11 AM, Nikolay Nikolov via fpc-pascal
> <fpc-pascal@lists.freepascal.org> wrote:
>
> ShortString is mainly for compatibility with Turbo Pascal, not for
> performance, IMHO. Although the FPC compiler itself still uses ShortString
> for performance reasons (I think the main advantage is the avoidance of the
> implicit try..finally blocks, needed for ansistrings). It might be
> interesting to benchmark the compiler with AnsiStrings instead of
> ShortStrings and see if there's a performance difference. But even if there
> is, a compiler is an extreme example. For 99% of the programs, performance
> impact of AnsiString is not an issue. I put {$H+} in almost all my new
> programs. I'd say that in 99% of the legit use cases, ShortString is used and
> needed for compatibility with legacy code, not for performance. Switching
> legacy code to {$H+} doesn't always work and may need additional fixes. Old
> code does things like S[0] := x instead of SetLength(S, x), etc. It also does
> uglier things, like FillChar() or Move() directly to/from string memory, or
> saves ShortStrings to files, as a part of
a record, etc.
One thing I can think of now is that adding an AnsiString to a record or class
makes that type "managed" and so it needs extra finalization when going out of
scope. Static arrays will need to finalize their members too and the RTL has to
do extra work in the lists classes to ensure this happens , which bloats the
generic container types.
Regards,
Ryan Joseph
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal