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)
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. */
30 typedef void *POINTER
;
31 #define EXCEEDS_LISP_PTR(x) 0
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.
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. */
52 check_memory_limits ()
55 extern POINTER (*real_morecore
) ();
57 extern POINTER (*__morecore
) ();
61 unsigned long five_percent
;
62 unsigned long data_size
;
66 five_percent
= lim_data
/ 20;
68 /* Find current end of memory and issue warning if getting near max */
71 cp
= (char *) (*real_morecore
) (0);
74 cp
= (char *) (*__morecore
) (0);
75 data_size
= (char *) cp
- (char *) data_space_start
;
81 if (data_size
> five_percent
* 15)
84 (*warn_function
) ("Warning: past 75% of memory limit");
89 if (data_size
> five_percent
* 17)
92 (*warn_function
) ("Warning: past 85% of memory limit");
97 if (data_size
> five_percent
* 19)
100 (*warn_function
) ("Warning: past 95% of memory limit");
105 (*warn_function
) ("Warning: past acceptable memory limits");
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)
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)
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)
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. */
130 memory_warnings (start
, warnfun
)
134 extern void (* __after_morecore_hook
) (); /* From gmalloc.c */
137 data_space_start
= start
;
139 data_space_start
= start_of_data ();
141 warn_function
= warnfun
;
142 __after_morecore_hook
= check_memory_limits
;
145 /* Force data limit to be recalculated on each run. */
150 /* arch-tag: eab04eda-1f69-447a-8d9f-95f0a3983ca5
151 (do not change this comment) */