If I look in perlvar it says:
$^M By default, running out of memory is an untrappable, fatal error. However, if suitably built, Perl can use the contents of $^M as an emergency memory pool after die()ing. Suppose that your Perl were compiled with - DPERL_EMERGENCY_SBRK and used Perl's malloc. Then $^M = 'a' x (1 << 16); would allocate a 64K buffer for use in an emergency. See the INSTALL file in the Perl distribution for information on how to enable this option. To discourage casual use of this advanced feature, there is no English long name for this variable.
Okay, of to look in INSTALL.... Nada! Not a dicky bird!
Soooo....grep the entire source tree.
changes5.004: Title: "Document $^M in perlvar" emacs\cperl-mode.el:$^M A buffer for emergency memory allocation w +hen running out of memory. lib\text\balanced\t\extvar.t:$^M; malloc.c: # Enable code for an emergency memory pool in $^M. See p +erlvar.pod malloc.c: # for a description of $^M. malloc.c: # PERL_EMERGENCY_SBRK is enabled) without touching $^M. +See malloc.c: # perlvar.pod for a description of $^M. malloc.c: PerlIO_puts(PerlIO_stderr(),"Bad alignment of $^M!\n" +); malloc.c: PerlIO_puts(PerlIO_stderr(),"Bad alignment of $^M! +\n"); pod\perl5004delta.pod:=item $^M pod\perl5004delta.pod:compiled for this, Perl may use the contents of +C<$^M> as an emergency pod\perl5004delta.pod: $^M = 'a' x (1<<16); pod\perl5004delta.pod:variable C<$^M>. See L<"$^M">. pod\perl5004delta.pod:However, if compiled for this, Perl may use the +contents of C<$^M> as pod\perldiag.pod:However, if compiled for this, Perl may use the conte +nts of C<$^M> as an pod\perltoc.pod:$SYSTEM_FD_MAX, $^F, $^H, %^H, $INPLACE_EDIT, $^I, $^M +, $OSNAME, $^O, pod\perltoc.pod:$^E, $^H, $^M pod\perlvar.pod:=item $^M pod\perlvar.pod:However, if suitably built, Perl can use the contents +of C<$^M> pod\perlvar.pod: $^M = 'a' x (1 << 16); win32\html\pod\perl5004delta.html:<dt><strong><a name="item__24_5em">$ +^M</a></strong><br /> win32\html\pod\perl5004delta.html:compiled for this, Perl may use the +contents of <a href="#item__24_5em"><pre>$^M</pre></a> as an emergenc +y win32\html\pod\perl5004delta.html: $^M = 'a' x (1<<16);</pre> win32\html\pod\perl5004delta.html:variable <a href="#item__24_5em"><pr +e>$^M</pre></a>. See <a href="#__m">$^M</a>. win32\html\pod\perl5004delta.html:However, if compiled for this, Perl +may use the contents of <a href="#item__24_5em"><pre>$^M</pre></a> as win32\html\pod\perldiag.html:However, if compiled for this, Perl may u +se the contents of <a href="file://e|\perl5.8.1-rc4\html/pod/perlvar. +html#item__24_5em"><pre>$^M</pre></a> as an win32\html\pod\perltoc.html:$SYSTEM_FD_MAX, $^F, $^H, %^H, $INPLACE_ED +IT, $^I, $^M, $OSNAME, $^O, win32\html\pod\perltoc.html:$^E, $^H, $^M win32\html\pod\perlvar.html:<dt><strong><a name="item__24_5em">$^M</a> +</strong><br /> win32\html\pod\perlvar.html:However, if suitably built, Perl can use t +he contents of <a href="#item__24_5em"><pre>$^M</pre></a> win32\html\pod\perlvar.html: $^M = 'a' x (1 << 16);</pre>
Hmm. Essential several repeitions of the same passage from perlvar... ponder... what other keywords... PERL_EMERGENCY_SBRK. Try that and you get exactly the same hits as for $^M.
Then I thought about it a little.
If I assign $^M = chr(0) x 2**20; what does that do? From the (sparse) documentation it suggests that it grabs a meg of ram and holds it in reserve... then, if at somepoint during my program something I do causes perl to try and allocate some memory and it fails, it has a 1 MB 'reserve' that will allow it to continue....
Hang on!
If I grab 1 MB up front, to give perl a reserve to draw on, doesn't that just mean that malloc will fail 1 MB earlier than it would have?
So great, now perl knows it's running out of memory and has switched to the reserve tank.... but unless I--or rather my program does something different--that just means that it will carry on doing what it's doing and run out anyway! And without some way for my (program) knowing that perl has switched to the reserve tank, I'm gonna carry on tanking down the highway to oblivion.
Hmmm. Maybe there is someway to 'obtain' that notification... I could wrap everything that causes memory allocation into an eval and watch for the infamous "out of memory" error? Gonna make the program kind of messy, not to mention the problems with scoping.
Maybe I could tie $^M and trap attempts to access it? Will such magic be invoked if it is perl that is accessing it? Seems unlikely.
April Fool!
Is there a way to use $^M to good effect, or is the use of the word 'advanced' in
To discourage casual use of this advanced feature, there is no English long name for this variable.
a euphemism for "April Fool!"?
An aside
As an aside, recently, when I needed to test huge file support, I discovered that I simply didn't have enough free space on any given partition on my drive to accomodate a file of > 4 GB, which was a pain. Then inspiration struck. My filesystem supports compression. If a file consists of all the same char, it should compress pretty well, so I used a perl one-liner to write a 10 GB file that consisted of all nulls (chr(0)), and sure enough it worked. I have a file that perl reports the size of as 10 GB but that only consume 5 MB of diskspace. Perfect for testing.
That made me think about my swap file. If I create my swap file on a compressed partition, and then use perl to allocate say 100 huge scalars my $buf1 = chr(0) x 100 * 2**20;, then once each scalar gets swapped out, it would be compressed pretty small.
Now I have a program running with 10 GB of memory, which ain't bad for a 32-bit box. All I need now is a way to make use of all that RAM:)
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is $^M a leftover April Fool?
by perrin (Chancellor) on Aug 30, 2003 at 00:30 UTC | |
by BUU (Prior) on Aug 30, 2003 at 00:51 UTC | |
by BrowserUk (Patriarch) on Aug 30, 2003 at 02:34 UTC | |
by perrin (Chancellor) on Aug 30, 2003 at 05:02 UTC | |
by BrowserUk (Patriarch) on Aug 30, 2003 at 06:52 UTC | |
by perrin (Chancellor) on Aug 30, 2003 at 00:57 UTC | |
Re: Is $^M a leftover April Fool?
by Elian (Parson) on Sep 01, 2003 at 17:01 UTC | |
by BrowserUk (Patriarch) on Sep 01, 2003 at 17:12 UTC | |
by Elian (Parson) on Sep 02, 2003 at 14:44 UTC | |
Re: Is $^M a leftover April Fool?
by rir (Vicar) on Jan 06, 2005 at 14:46 UTC | |
by BrowserUk (Patriarch) on Jan 06, 2005 at 14:58 UTC | |
by merlyn (Sage) on Jan 06, 2005 at 15:03 UTC | |
by BrowserUk (Patriarch) on Jan 06, 2005 at 15:14 UTC | |
by rir (Vicar) on Jan 06, 2005 at 19:39 UTC | |
| |
by dragonchild (Archbishop) on Jan 06, 2005 at 15:12 UTC | |
by duff (Parson) on Jan 06, 2005 at 15:39 UTC | |
by Anonymous Monk on Jan 06, 2005 at 16:06 UTC | |
by duff (Parson) on Jan 06, 2005 at 15:12 UTC | |
by Jenda (Abbot) on Jan 06, 2005 at 18:06 UTC | |
Re: Is $^M a leftover April Fool?
by bluto (Curate) on Jan 06, 2005 at 22:42 UTC | |
by BrowserUk (Patriarch) on Jan 06, 2005 at 23:26 UTC |