(Info-fontify-node): Set 2nd arg `noerror' of `Info-find-file' to t.
[emacs.git] / src / vm-limit.c
blob0c12dec9b046a911d8ff4726b3956e1dac5e24f4
1 /* Functions for memory limit warnings.
2 Copyright (C) 1990, 1992, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #ifdef emacs
23 #include <config.h>
24 #include "lisp.h"
25 #endif
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
34 #include "mem-limits.h"
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.
43 static int warnlevel;
45 /* Function to call to issue a warning;
46 0 means don't issue them. */
47 static void (*warn_function) ();
49 /* Get more memory space, complaining if we're near the end. */
51 static void
52 check_memory_limits ()
54 #ifdef REL_ALLOC
55 extern POINTER (*real_morecore) ();
56 #endif
57 extern POINTER (*__morecore) ();
60 register POINTER cp;
61 unsigned long five_percent;
62 unsigned long data_size;
64 if (lim_data == 0)
65 get_lim_data ();
66 five_percent = lim_data / 20;
68 /* Find current end of memory and issue warning if getting near max */
69 #ifdef REL_ALLOC
70 if (real_morecore)
71 cp = (char *) (*real_morecore) (0);
72 else
73 #endif
74 cp = (char *) (*__morecore) (0);
75 data_size = (char *) cp - (char *) data_space_start;
77 if (warn_function)
78 switch (warnlevel)
80 case 0:
81 if (data_size > five_percent * 15)
83 warnlevel++;
84 (*warn_function) ("Warning: past 75% of memory limit");
86 break;
88 case 1:
89 if (data_size > five_percent * 17)
91 warnlevel++;
92 (*warn_function) ("Warning: past 85% of memory limit");
94 break;
96 case 2:
97 if (data_size > five_percent * 19)
99 warnlevel++;
100 (*warn_function) ("Warning: past 95% of memory limit");
102 break;
104 default:
105 (*warn_function) ("Warning: past acceptable memory limits");
106 break;
109 /* If we go down below 70% full, issue another 75% warning
110 when we go up again. */
111 if (data_size < five_percent * 14)
112 warnlevel = 0;
113 /* If we go down below 80% full, issue another 85% warning
114 when we go up again. */
115 else if (warnlevel > 1 && data_size < five_percent * 16)
116 warnlevel = 1;
117 /* If we go down below 90% full, issue another 95% warning
118 when we go up again. */
119 else if (warnlevel > 2 && data_size < five_percent * 18)
120 warnlevel = 2;
122 if (EXCEEDS_LISP_PTR (cp))
123 (*warn_function) ("Warning: memory in use exceeds lisp pointer size");
126 /* Cause reinitialization based on job parameters;
127 also declare where the end of pure storage is. */
129 void
130 memory_warnings (start, warnfun)
131 POINTER start;
132 void (*warnfun) ();
134 extern void (* __after_morecore_hook) (); /* From gmalloc.c */
136 if (start)
137 data_space_start = start;
138 else
139 data_space_start = start_of_data ();
141 warn_function = warnfun;
142 __after_morecore_hook = check_memory_limits;
144 #ifdef WINDOWSNT
145 /* Force data limit to be recalculated on each run. */
146 lim_data = 0;
147 #endif
150 /* arch-tag: eab04eda-1f69-447a-8d9f-95f0a3983ca5
151 (do not change this comment) */