1 /* Functions for memory limit warnings.
2 Copyright (C) 1990, 1992 Free Software Foundation, Inc.
5 This file is part of the GNU C Library.
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License as
9 published by the Free Software Foundation; either version 2 of the
10 License, or (at your option) any later version.
12 The GNU C Library 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 GNU
15 Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with the GNU C Library; see the file COPYING.LIB. If
19 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
20 Cambridge, MA 02139, 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 ()
54 extern POINTER (*__morecore
) ();
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
;
72 if (data_size
> five_percent
* 15)
75 (*warn_function
) ("Warning: past 75% of memory limit");
80 if (data_size
> five_percent
* 17)
83 (*warn_function
) ("Warning: past 85% of memory limit");
88 if (data_size
> five_percent
* 19)
91 (*warn_function
) ("Warning: past 95% of memory limit");
96 (*warn_function
) ("Warning: past acceptable memory limits");
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)
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)
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)
113 if (EXCEEDS_LISP_PTR (cp
))
114 (*warn_function
) ("Warning: memory in use exceeds lisp pointer size");
117 /* Cause reinitialization based on job parameters;
118 also declare where the end of pure storage is. */
121 memory_warnings (start
, warnfun
)
125 extern void (* __after_morecore_hook
) (); /* From gmalloc.c */
128 data_space_start
= start
;
130 data_space_start
= start_of_data ();
132 warn_function
= warnfun
;
133 __after_morecore_hook
= check_memory_limits
;