Perl:现实生活中的字符串长度限制 [英] Perl: string length limitations in real life

查看:289
本文介绍了Perl:现实生活中的字符串长度限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,在 perldata 文档中,Perl中的标量字符串仅受可用内存限制,我强烈建议怀疑现实生活中还有其他限制.

While, for example, perldata documents that scalar strings in Perl are limited only by available memory, I'm strongly suspecting in real life there would be some other limits.

我正在考虑以下想法:

  • 我不确定Perl中如何实现字符串-是否存在某种字节/字符计数器?如果存在,则可能将其实现为平台相关的整数(即32位或64位),因此有效地它将字符串限制为2 ** 312 ** 322 ** 632 ** 64字节
  • 如果Perl不使用计数器,而是使用某个字节来终止字符串(这很奇怪,因为在Perl中使用"foo \ 0bar"之类的字符串是完全可以的),那么所有操作都将不可避免地得到随着字符串长度的增加,速度要慢得多.
  • Perl处理字符串的大多数字符串函数,例如 length ,例如,返回正常的标量整数,而且我强烈怀疑它也是平台限制的整数.
  • I'm not sure how strings are implemented in Perl — is there some sort of byte/character counter? If there is, then probably it's implemented as a platform-dependent integer (i.e. 32-bit or 64-bit), so effectively it would limit strings to something like 2 ** 31, 2 ** 32, 2 ** 63 or 2 ** 64 bytes.
  • If Perl doesn't use a counter and instead uses some byte to terminate the string (which would be strange, as it's perfectly ok to have a string like "foo\0bar" in Perl), then all operations would inevitably get much slower as string length increases.
  • Most string functions that Perl deals with strings, such as length, for example, return normal scalar integer, and I strongly suspect that it would be platform-limited integer too.

那么,在现实生活中限制Perl字符串长度的其他因素是什么?出于实用目的,应该考虑什么字符串长度?

So, what would be the other factors that limit Perl string length in real life? What should be considered an okay string length for practical purposes?

推荐答案

它跟踪缓冲区的大小和其中的字节数.

It keep track of the size of the buffer and the number of bytes therein.

$ 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

  • 在Perl的32位版本上,这些值使用32位无符号整数. (恰好)足够大,可以创建一个用尽了整个进程4 GiB地址空间的字符串.

    • On a 32-bit build of Perl, it uses 32-bit unsigned integer for these values. This is (exactly) large enough to create a string that uses up your process's entire 4 GiB address space.

      在Perl的64位版本上,这些值使用64位无符号整数. (完全)足够大,可以创建一个使用整个进程的整个16个 EiB 地址空间的字符串.

      On a 64-bit build of Perl, it uses 64-bit unsigned integer for those values. This is (exactly) large enough to create a string that uses up your process's entire 16 EiB address space.

      该文档是正确的.字符串的大小仅受可用内存的限制.

      The docs are correct. The size of the string is limited only by available memory.

      这篇关于Perl:现实生活中的字符串长度限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆