Perl: string length limits in real life

So far, for example, perldata documents that scalars in Perl are limited only by available memory, I strongly suspect that in real life there will be some other restrictions.

I consider the following ideas:

  • I'm not sure how strings are implemented in Perl - is there any byte / character count? If there is, then it is probably implemented as a platform-specific integer (for example, 32-bit or 64-bit), so it will limit the strings to 2 ** 31 , 2 ** 32 , 2 ** 63 or 2 ** 64 bytes.
  • If Perl does not use a counter and instead uses some byte to break the line (which would be strange since it is normal to have a line like "foo \ 0bar" in Perl), then all operations will inevitably be much slower as the length of the line increases.
  • Most of the string functions that Perl deals with strings, such as length , for example, return a normal integer scalar number, and I strongly suspect that it will be a platform-limited integer.

So, what would be other factors limiting Perl string length in real life? What can be considered a good string length for practical purposes?

+7
string perl limit
source share
1 answer

It keeps track of the size of the buffer and the number of bytes in it.

 $ perl -MDevel::Peek -e'$x="abcdefghij"; Dump($x);' SV = PV(0x9222b00) at 0x9222678 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x9238220 "abcdefghij"\0 CUR = 10 <-- 10 bytes used LEN = 12 <-- 12 bytes allocated 
  • The Perl 32-bit assembly uses an unsigned 32-bit integer for these values. This is (accurately) large enough to create a string that uses your process with just 4 GiB address spaces.

  • The 64-bit Perl assembly uses an unsigned 64-bit integer for these values. This is (accurately) large enough to create a row that uses your entire process for a total of 16 EiB .

The documents are correct. Line size is limited only by available memory.

+14
source share

All Articles