Perl无法在具有32 GB RAM的Snow leopard Mac服务器上分配超过1.1 GB的空间

前端之家收集整理的这篇文章主要介绍了Perl无法在具有32 GB RAM的Snow leopard Mac服务器上分配超过1.1 GB的空间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一台32GB内存的Mac服务器(雪豹).当我尝试在Perl(v 5.10.0)中分配超过1.1GB的RAM时,出现内存不足错误.这是我使用的脚本:

#!/usr/bin/env perl

# My snow leopard MAC server runs out of memory at >1.1 billion bytes.  How
# can this be when I have 32 GB of memory installed?  Allocating up to 4
# billion bytes works on a Dell Win7 12GB RAM machine.

# perl -v
# This is perl,v5.10.0 built for darwin-thread-multi-2level
# (with 2 registered patches,see perl -V for more detail)

use strict;
use warnings;

my $s;
print "Trying 1.1 GB...";
$s = "a" x 1100000000;   # ok
print "OK\n\n";

print "Trying 1.2 GB...";
$s = '';
$s = "a" x 1200000000;   # fails
print "..OK\n";

这是我得到的输出

Trying 1.1 GB...OK

perl(96685) malloc: *** mmap(size=1200001024) Failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Out of memory!
Trying 1.2 GB...

任何想法为什么会这样?

13/14/13更新时间:下午4:42

根据Kent Fredric(见下面的2篇文章),这是我的ulimits.虚拟内存默认为无限制

$ulimit -a | grep bytes
data seg size           (kbytes,-d) unlimited
max locked memory       (kbytes,-l) unlimited
max memory size         (kbytes,-m) unlimited
pipe size            (512 bytes,-p) 1
stack size              (kbytes,-s) 8192
virtual memory          (kbytes,-v) unlimited

$perl -E 'my $x = "a" x 1200000000; print "ok\n"'
perl(23074) malloc: *** mmap(size=1200001024) Failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Out of memory!

$perl -E 'my $x = "a" x 1100000000; print "ok\n"'
ok

我尝试将虚拟内存设置为100亿但无济于事.

$ulimit -v 10000000000   # 10 billion

$perl -E 'my $x = "a" x 1200000000; print "ok\n"'
perl(24275) malloc: *** mmap(size=1200001024) Failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Out of memory!

解决方法

您正在使用32位构建的Perl(如perl -V:ptrsize所示),但您需要64位构建.我建议使用 perlbrew安装本地perl.

这可以通过在安装Perl时将-Duse64bitall传递给Configure来实现.

这可以通过在安装Perl时将–64all传递给perlbrew安装来实现.

(出于一些奇怪的原因,perl -V:use64bitall说这已经完成,但显然不是.)

猜你在找的Perl相关文章