1 /* Functions for memory limit warnings.
2 Copyright (C) 1990, 1992 Free Software Foundation, Inc.
4 This file is part of SXEmacs
6 SXEmacs 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 3 of the License, or
9 (at your option) any later version.
11 SXEmacs 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 this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Synched up with: FSF 19.30. */
30 typedef void *POINTER;
31 #define EXCEEDS_LISP_PTR(x) 0
34 #include "mem-limits.h"
36 #ifdef HAVE_MALLOC_WARNING
38 Level number of warnings already issued.
39 0 -- no warnings issued.
40 1 -- 75% warning already issued.
41 2 -- 85% warning already issued.
42 3 -- 95% warning issued; keep warning frequently.
46 /* Function to call to issue a warning;
47 0 means don't issue them. */
48 static void (*warn_function) (const char *);
50 /* Get more memory space, complaining if we're near the end. */
51 static void check_memory_limits(void)
53 extern POINTER(*__morecore) (ptrdiff_t size);
56 unsigned long five_percent;
57 unsigned long data_size;
58 void (*save_warn_fun) (const char *);
62 five_percent = lim_data / 20;
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;
69 /* temporarily reset the warn_function to 0 or we will get infinite
71 save_warn_fun = warn_function;
75 if (data_size > five_percent * 15) {
78 ("Warning: past 75% of memory limit");
83 if (data_size > five_percent * 17) {
86 ("Warning: past 85% of memory limit");
91 if (data_size > five_percent * 19) {
94 ("Warning: past 95% of memory limit");
100 ("Warning: past acceptable memory limits");
103 warn_function = save_warn_fun;
106 /* If we go down below 70% full, issue another 75% warning
107 when we go up again. */
108 if (data_size < five_percent * 14)
110 /* If we go down below 80% full, issue another 85% warning
111 when we go up again. */
112 else if (warnlevel > 1 && data_size < five_percent * 16)
114 /* If we go down below 90% full, issue another 95% warning
115 when we go up again. */
116 else if (warnlevel > 2 && data_size < five_percent * 18)
119 if (EXCEEDS_LISP_PTR(cp)) {
121 /* temporarily reset the warn_function to 0 or we will get infinite
123 save_warn_fun = warn_function;
126 ("Warning: memory in use exceeds lisp pointer size");
127 warn_function = save_warn_fun;
131 #endif /* HAVE_MALLOC_WARNING */
133 /* Cause reinitialization based on job parameters;
134 also declare where the end of pure storage is. */
136 void memory_warnings(void *start, void (*warnfun) (const char *))
138 #ifdef HAVE_MALLOC_WARNING
139 extern void (*__after_morecore_hook) (void); /* From gmalloc.c */
143 data_space_start = (char *)start;
145 data_space_start = start_of_data();
147 #ifdef HAVE_MALLOC_WARNING
148 warn_function = warnfun;
149 __after_morecore_hook = check_memory_limits;