view src/vm-limit.c @ 67483:b6000aca7291

Set VER to `22.1'. (Basic editing): Explain how to use localized versions of the Tutorial. Mention that `C-h r' displays the manual. Delete obsolete WWW link to an Emacs 18 tutorial. (Getting a printed manual): Point to the new locations of the manuals on the GNU Web site. (Emacs Lisp documentation): Explain that the Emacs Lisp manual is available via Info (it was previously distributed separately). (Installing Texinfo documentation): The latest version of Texinfo is 4.8, not 4.0. (Informational files for Emacs): COPYING is the GNU General Public License, not the Emacs General Public License. (Informational files for Emacs): Delete obsolete link to the GNUinfo pages as they have been removed from the GNU Web site. (New in Emacs 22): New node. (Setting up a customization file): Say that most packages support Customize nowadays. (Colors on a TTY): Delete reference to instructions on how to enable syntax highlighting, it is now enabled by default. (Turning on abbrevs by default): Emacs now reads the abbrevs file at startup automatically. (Controlling case sensitivity): Mention `M-c' in isearch. (Using an already running Emacs process): Emacs now creates the socket in `/tmp/emacsUID'. Fix typos. Change default location of gnuserv. As emacsclient can now run Lisp code as well, delete a sentence praising gnuserv for that. Simplify description of how the client/server operation works. (Compiler error messages): Delete obsolete text (compile.el has been rewritten). (Indenting switch statements): Fix typo. (Matching parentheses): Simplify setup instructions, mention the menu bar item in the Options menu. (Repeating a command as many times as possible): Mention `C-x e'. (Going to a line by number): Mention new keymap and bindings `M-g M-g', `M-g M-p' and `M-g M-n'. (Turning on syntax highlighting): Now on by default. Simplify. (Replacing highlighted text): Use `1', not `t'. (Problems with very large files): The maximum size is now 256MB on 32-bit machines. (^M in the shell buffer): Mention `comint-process-echoes'. (Emacs for Apple computers): Emacs 22 has native support for Mac OS X. (Translating names to IP addresses): Delete node. (Binding keys to commands): Fix typo. (SPC no longer completes file names): New node. (MIME with Emacs mail packages): Delete section about the Emacs MIME FAQ (it's not reachable anymore).
author Romain Francoise <romain@orebokech.com>
date Sat, 10 Dec 2005 21:21:30 +0000
parents a0d1312ede66
children 3bd95f4f2941 2d92f5c9d6ae
line wrap: on
line source

/* Functions for memory limit warnings.
   Copyright (C) 1990, 1992, 2002, 2003, 2004,
                 2005 Free Software Foundation, Inc.

This file is part of GNU Emacs.

GNU Emacs is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.  */

#ifdef emacs
#include <config.h>
#include "lisp.h"
#endif

#ifndef emacs
#include <stddef.h>
typedef size_t SIZE;
typedef void *POINTER;
#define EXCEEDS_LISP_PTR(x) 0
#endif

#include "mem-limits.h"

/*
  Level number of warnings already issued.
  0 -- no warnings issued.
  1 -- 75% warning already issued.
  2 -- 85% warning already issued.
  3 -- 95% warning issued; keep warning frequently.
*/
static int warnlevel;

/* Function to call to issue a warning;
   0 means don't issue them.  */
static void (*warn_function) ();

/* Get more memory space, complaining if we're near the end. */

static void
check_memory_limits ()
{
#ifdef REL_ALLOC
  extern POINTER (*real_morecore) ();
#endif
  extern POINTER (*__morecore) ();


  register POINTER cp;
  unsigned long five_percent;
  unsigned long data_size;

  if (lim_data == 0)
    get_lim_data ();
  five_percent = lim_data / 20;

  /* Find current end of memory and issue warning if getting near max */
#ifdef REL_ALLOC
  if (real_morecore)
    cp = (char *) (*real_morecore) (0);
  else
#endif
  cp = (char *) (*__morecore) (0);
  data_size = (char *) cp - (char *) data_space_start;

  if (warn_function)
    switch (warnlevel)
      {
      case 0:
	if (data_size > five_percent * 15)
	  {
	    warnlevel++;
	    (*warn_function) ("Warning: past 75% of memory limit");
	  }
	break;

      case 1:
	if (data_size > five_percent * 17)
	  {
	    warnlevel++;
	    (*warn_function) ("Warning: past 85% of memory limit");
	  }
	break;

      case 2:
	if (data_size > five_percent * 19)
	  {
	    warnlevel++;
	    (*warn_function) ("Warning: past 95% of memory limit");
	  }
	break;

      default:
	(*warn_function) ("Warning: past acceptable memory limits");
	break;
      }

  /* If we go down below 70% full, issue another 75% warning
     when we go up again.  */
  if (data_size < five_percent * 14)
    warnlevel = 0;
  /* If we go down below 80% full, issue another 85% warning
     when we go up again.  */
  else if (warnlevel > 1 && data_size < five_percent * 16)
    warnlevel = 1;
  /* If we go down below 90% full, issue another 95% warning
     when we go up again.  */
  else if (warnlevel > 2 && data_size < five_percent * 18)
    warnlevel = 2;

  if (EXCEEDS_LISP_PTR (cp))
    (*warn_function) ("Warning: memory in use exceeds lisp pointer size");
}

/* Cause reinitialization based on job parameters;
   also declare where the end of pure storage is. */

void
memory_warnings (start, warnfun)
     POINTER start;
     void (*warnfun) ();
{
  extern void (* __after_morecore_hook) ();     /* From gmalloc.c */

  if (start)
    data_space_start = start;
  else
    data_space_start = start_of_data ();

  warn_function = warnfun;
  __after_morecore_hook = check_memory_limits;

#ifdef WINDOWSNT
  /* Force data limit to be recalculated on each run.  */
  lim_data = 0;
#endif
}

/* arch-tag: eab04eda-1f69-447a-8d9f-95f0a3983ca5
   (do not change this comment) */