in reply to Is $^M a leftover April Fool?

As I understand it, this feature exists to allow you to try and figure out where and why your program is running out of memory, and maybe do some emergency cleanup. Perl will die() when it fails to malloc, but the die can be caught by a DIE signal handler which can print a stack trace. It's not very fashionable to use DIE handlers these days because of the tricky issues around using them with eval{} blocks, but it seems like you could get it to work if you really needed it.

Replies are listed 'Best First'.
Re: Re: Is $^M a leftover April Fool?
by BUU (Prior) on Aug 30, 2003 at 00:51 UTC
    The docs seem to support what you said, but according to BrowserUK theres no trace of that functionality in the actual source code. Do you have some counter evidence?

      I wasn't suggesting that it isn't there. As perrin points out, it's right there in malloc.c at the top of the grep listing I included.

      My problem is

      1. The almost complete absence of documentation.
      2. It's useablilty (or lack thereof).

      A little more documentation outlining under what circumstances it can be used--which perl build options are required for it to be enabled etc.--plus some indication of how one might use it would go a long way.

      Perhaps because Win32-perl generally translates to AS perl which doesn't appear to be built with the PERL_EMERGENCY_SBRK option enabled, and the facility hasn't been exercised under Win32.

      Maybe because sbrk(2) is a *nix system thing and Win32 doesn't have any equivalent?

      Try as I might, I can't persuade $^M to do anything, at least not that I can detect.

      It is quite difficult to tell as when you have swapping enabled, you can allocate an aweful lot of memory before you run out, but by the time you do, the system has become quite unresponsive, so actually detecting the point of failure is very hard. I tried setting a %SIG{__DIE__} handler that use Carp::croak() to give me a trace back, but I never saw it.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "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.

        It looks to me like you are simply not the target audience. The target audience is madmen who are so desperate to figure out where their programs are running out of memory that they are willing to look at malloc.c. This is clearly a last resort thing that no sane person would ever require, given the many other ways to debug a program.

        Anyway, the docs do say that your Perl has to be built with -DPERL_EMERGENCY_SBRK and with Perl's malloc selected, so if you're AS build was not done that way, you can't expect it to work for you.

      It's right there in malloc.c. Look for "emergency_sbrk".