(iso-transl-dead-key-alist): Fix syntax for ?^.
[emacs.git] / src / vm-limit.c
blobb23beeb26e7710f16ba97624cf0c9fd88ff6d2a3
1 /* Functions for memory limit warnings.
2 Copyright (C) 1990, 1992 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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.
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.
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, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #ifdef emacs
22 #include <config.h>
23 #include "lisp.h"
24 #endif
26 #ifndef emacs
27 #include <stddef.h>
28 typedef size_t SIZE;
29 typedef void *POINTER;
30 #define EXCEEDS_LISP_PTR(x) 0
31 #endif
33 #include "mem-limits.h"
36 Level number of warnings already issued.
37 0 -- no warnings issued.
38 1 -- 75% warning already issued.
39 2 -- 85% warning already issued.
40 3 -- 95% warning issued; keep warning frequently.
42 static int warnlevel;
44 /* Function to call to issue a warning;
45 0 means don't issue them. */
46 static void (*warn_function) ();
48 /* Get more memory space, complaining if we're near the end. */
50 static void
51 check_memory_limits ()
53 extern POINTER (*__morecore) ();
55 register POINTER cp;
56 unsigned long five_percent;
57 unsigned long data_size;
59 if (lim_data == 0)
60 get_lim_data ();
61 five_percent = lim_data / 20;
63 /* Find current end of memory and issue warning if getting near max */
64 cp = (char *) (*__morecore) (0);
65 data_size = (char *) cp - (char *) data_space_start;
67 if (warn_function)
68 switch (warnlevel)
70 case 0:
71 if (data_size > five_percent * 15)
73 warnlevel++;
74 (*warn_function) ("Warning: past 75% of memory limit");
76 break;
78 case 1:
79 if (data_size > five_percent * 17)
81 warnlevel++;
82 (*warn_function) ("Warning: past 85% of memory limit");
84 break;
86 case 2:
87 if (data_size > five_percent * 19)
89 warnlevel++;
90 (*warn_function) ("Warning: past 95% of memory limit");
92 break;
94 default:
95 (*warn_function) ("Warning: past acceptable memory limits");
96 break;
99 /* If we go down below 70% full, issue another 75% warning
100 when we go up again. */
101 if (data_size < five_percent * 14)
102 warnlevel = 0;
103 /* If we go down below 80% full, issue another 85% warning
104 when we go up again. */
105 else if (warnlevel > 1 && data_size < five_percent * 16)
106 warnlevel = 1;
107 /* If we go down below 90% full, issue another 95% warning
108 when we go up again. */
109 else if (warnlevel > 2 && data_size < five_percent * 18)
110 warnlevel = 2;
112 if (EXCEEDS_LISP_PTR (cp))
113 (*warn_function) ("Warning: memory in use exceeds lisp pointer size");
116 /* Cause reinitialization based on job parameters;
117 also declare where the end of pure storage is. */
119 void
120 memory_warnings (start, warnfun)
121 POINTER start;
122 void (*warnfun) ();
124 extern void (* __after_morecore_hook) (); /* From gmalloc.c */
126 if (start)
127 data_space_start = start;
128 else
129 data_space_start = start_of_data ();
131 warn_function = warnfun;
132 __after_morecore_hook = check_memory_limits;