title: Perl cannot allocate more than 1.1 GB on a Snow leopard Mac server with 32 GB RAM
body: <p>I have a Mac server (snow leopard) with 32GB RAM. When I try to allocate more than 1.1GB RAM in Perl (v 5.10.0) I get an out of memory error. Here is the script that I used: </p>
  
  <pre><code>#!/usr/bin/env perl
  
  # My snow leopard MAC server runs out of memory at &gt;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";
  </code></pre>
  
  <p>Here is the output that I get:</p>
  
  <pre><code>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...
  </code></pre>
  
  <p>Any ideas why this is happening?</p>
  
  <hr>
  
  <p>UPDATE 4:42pm 11/14/13</p>
  
  <p>As per Kent Fredric (see 2 posts below), here are my ulimits. Virtual memory defaults to unlimited</p>
  
  <pre>
  $ 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
  </pre>
  
  <p>I tried setting virtual memory to 10 billion but to no avail.</p>
  
  <pre>
  $ 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!
  </pre>