home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.004 / xemacs-1 / xemacs-19.13 / src / vm-limit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-25  |  3.4 KB  |  135 lines

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