有没有一个标准的方式,Perl在内存不足时的行为? [英] Is there a standard way for perl to behave when it runs out of memory?

查看:193
本文介绍了有没有一个标准的方式,Perl在内存不足时的行为?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Perl解释器(也称为perl)是否有一种标准(ish)方式在内存不足时表现?是否以任何方式记录/指定?编码在一些统一的方式?



我对所表达的任何标准特别感兴趣,这些标准被表达为运行Perl代码的约定 - 例如,将 die 被调用?将执行 END 块?等等...



我对两个理论答案都很好(比如某种通用的这是一般的perl代码应该在外面的记忆任务声明文件从Larry / P5P / etc ...,即使不是100%的malloc()调用遵循这条规则);或实用语句(例如,Perl中的所有malloc()调用都被包含在通用的allocate_memory函数中,它统一处理所有故障)。



这可能是可能的答案取决于具体导致内存不足(例如,Perl代码的数据结构的更多内存请求与内部Perl代码分配的内存与Perl程序中显式需要存储更多数据逻辑无关)。



如果答案非常依赖于实现,则假定Solaris / Linux为perl,并且缩小到任何最近的稳定版本(5.8到5.16)是可以接受的。



问题仅限于标准的Perl解释器,但是您希望将其定义为预编译配置(例如,一个主要的Linux发行版附带的perl,或者一个编译的所有默认值,注意:这个问题来自于Gilles对另一个Q

解决方案

查看Perl将在使用诊断语法是什么时发出的各种诊断警告的手册页面启用,您可以看到各种不同类型的内存不足错误及其含义。



因此,您可以从这些消息中推断出标准行为;有一个感叹号(Out of memory!)听起来像你正在问的一个:

 内存不足! 
(X)malloc()函数返回0,表示有
剩余的内存(或虚拟内存)不足以满足
请求。 Perl不得不立即退出。

X级错误标记为非常致命的错误(不可接受)。 p>

但是,如果它是一个大请求(大于64K),它是可以捕获的(我猜Perl假定它有足够的内存可以干净地关机)。


Is there a standard(ish) way for a Perl interpreter (aka "perl") to behave when it runs out of memory? Is it documented/specced-out in any way? Coded in some uniform way?

I'm especially interested in any standards which are expressed as covenant to Perl code being run - e.g., will die be called? Will END block be executed? Etc...

I'm fine with both an "theoretical" answer (e.g. some sort of generic "this is what perl code ought to do in general on out-of-memory" mission statement document from Larry/P5P/etc..., even if not 100% of malloc() calls follow this rule); or a "practical" statement (e.g. all malloc() calls in Perl are wrapped into a generic "allocate_memory" function which uniformly handles all failures).

It may be possible that the answer depends on what specifically causes out of memory (e.g. a request for more memory for Perl code's data structure vs. memory allocated by internal Perl code unrelated to explicit "need to store more data" logic in Perl program).

If the answer is extremely implementation dependent, assume perl for Solaris/Linux,and narrowing down to any recent stable version (5.8 to 5.16) is acceptable.

The question is limited to standard Perl interpreter, however you wish to define that as far as pre-compile configuration (e.g. perl that comes with a major Linux distribution, or one compiled with all defaults left alone, etc...).

NOTE: This question came out of Gilles's comment to another Q

解决方案

Taking a look at the manual page for the various diagnostic warnings that Perl will issue when the "use diagnostics" pragma is enabled, you can see various different types of "out of memory" errors and what they mean.

So you can infer the "standard" behavior from these messages; the one with an exclamation point ("Out of memory!") sounds like the one you're asking about:

Out of memory!
(X) The malloc() function returned 0, indicating there was
insufficient remaining memory (or virtual memory) to satisfy the
request.  Perl has no option but to exit immediately.

An "X" level error is labeled as "A very fatal error (nontrappable)."

However if it's a "large request" (for greater than 64K) it is trappable (I guess Perl assumes it'll have enough memory to shutdown cleanly).

这篇关于有没有一个标准的方式,Perl在内存不足时的行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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