home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / src / vm-limit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-28  |  2.9 KB  |  127 lines

  1. /* Functions for memory limit warnings.
  2.    Copyright (C) 1990, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU Emacs.
  5.  
  6. GNU Emacs is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Emacs is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Emacs; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "config.h"
  21. #include "mem_limits.h"
  22. #include "lisp.h"
  23.  
  24. extern char etext;
  25.  
  26. #ifdef DATA_SEG_BITS
  27. #define EXCEEDS_ELISP_PTR(ptr) (((unsigned int) (ptr) >> VALBITS) \
  28.                 != (DATA_SEG_BITS >> VALBITS))
  29. #else
  30. #define EXCEEDS_ELISP_PTR(ptr) ((unsigned int) (ptr) >> VALBITS)
  31. #endif
  32.  
  33. /*
  34.   Level number of warnings already issued.
  35.   0 -- no warnings issued.
  36.   1 -- 75% warning already issued.
  37.   2 -- 85% warning already issued.
  38. */
  39. static int warnlevel;
  40.  
  41. /* Function to call to issue a warning;
  42.    0 means don't issue them.  */
  43. static void (*warnfunction) ();
  44.  
  45. extern POINTER sbrk ();
  46.  
  47. /* Get more memory space, complaining if we're near the end. */
  48.  
  49. static char *
  50. morecore_with_warning (size)
  51.      register int size;
  52. {
  53.   POINTER result;
  54.   register POINTER cp;
  55.   register unsigned int siz;
  56.  
  57.   if (!data_space_start)
  58.     {
  59.       data_space_start = start_of_data ();
  60.     }
  61.  
  62.   if (lim_data == 0)
  63.     get_lim_data ();
  64.  
  65.   /* Find current end of memory and issue warning if getting near max */
  66.   cp = sbrk (0);
  67.   siz = (char *)cp - (char *)data_space_start;
  68.  
  69.   if (warnfunction)
  70.     switch (warnlevel)
  71.       {
  72.       case 0: 
  73.     if (siz > (lim_data / 4) * 3)
  74.       {
  75.         warnlevel++;
  76.         (*warnfunction) ("Warning: past 75% of memory limit");
  77.       }
  78.     break;
  79.  
  80.       case 1: 
  81.     if (siz > (lim_data / 20) * 17)
  82.       {
  83.         warnlevel++;
  84.         (*warnfunction) ("Warning: past 85% of memory limit");
  85.       }
  86.     break;
  87.  
  88.       case 2: 
  89.     if (siz > (lim_data / 20) * 19)
  90.       {
  91.         warnlevel++;
  92.         (*warnfunction) ("Warning: past 95% of memory limit");
  93.       }
  94.     break;
  95.  
  96.       default:
  97.     (*warnfunction) ("Warning: past acceptable memory limits");
  98.     break;
  99.       }
  100.  
  101.   if (EXCEEDS_ELISP_PTR (cp))
  102.     (*warnfunction) ("Warning: memory in use exceeds lisp pointer size");
  103.  
  104.   result = sbrk (size);
  105.   if (result == (POINTER) -1)
  106.     return 0;
  107.   return result;
  108. }
  109.  
  110. extern char *(* __morecore) ();     /* From gmalloc.c */
  111.  
  112. /* Cause reinitialization based on job parameters;
  113.    also declare where the end of pure storage is. */
  114.  
  115. void
  116. malloc_init (start, warnfun)
  117.      POINTER start;
  118.      void (*warnfun) ();
  119. {
  120.   if (start)
  121.     data_space_start = start;
  122.   lim_data = 0;
  123.   warnlevel = 0;
  124.   warnfunction = warnfun;
  125.   __morecore = morecore_with_warning;
  126. }
  127.