[fpc-devel] Concatenating huge AnsiStrings

Virgo Pärna virgo.parna at mail.ee
Thu Jun 27 09:42:33 CEST 2024


On Fri, 21 Jun 2024 20:03:56 +0200, Marco van de Voort via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
> Probably terminate with a heap out of memory error.

Also depends of platform...

program tests;
var
  s, s1, s2: ansistring;
begin
  SetLength(s1, High(int32));
  SetLength(s2, High(int32));
  WriteLn(Length(s1));
  WriteLn(Length(s2));
  s := s1 + s2;
  WriteLn(Length(s));
end.

Works as 64 bit Windows program:
2147483647
2147483647
4294967294

But gets "Runtime error 203 at $00404A01" on 32 bit Windows (out of
memory).

I did not actually know, that string length was 64 bits on 64 bit
platform (at least on Windows), because even uint worked. uint32 version
of same code generated warning at compile time. And uint32 version of
same code results in strings with length 0. Because sizeint is signed.

I do not have access to 64 bit Delphi, but Embarcadero RAD Studio Athena
documentation claims, that there ansistring length is limitud to "~2^31
characters". And there is no implication, that 64 bit has different
maximum.

-- 
Virgo Pärna 
virgo.parna at mail.ee



More information about the fpc-devel mailing list