*** empty log message ***
[emacs.git] / src / vm-limit.c
blob496e392e5b0c5ab6436f4f50e2497eb610d0d7da
1 /* Functions for memory limit warnings.
2 Copyright (C) 1990 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 1, 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 #include "config.h"
21 #include "lisp.h"
22 #include "mem_limits.h"
25 Level number of warnings already issued.
26 0 -- no warnings issued.
27 1 -- 75% warning already issued.
28 2 -- 85% warning already issued.
30 static int warnlevel;
32 /* Function to call to issue a warning;
33 0 means don't issue them. */
34 static void (*warnfunction) ();
36 extern POINTER sbrk ();
38 /* Get more memory space, complaining if we're near the end. */
40 static POINTER
41 morecore_with_warning (size)
42 register int size;
44 POINTER result;
45 register POINTER cp;
46 register unsigned int siz;
48 if (!data_space_start)
50 data_space_start = start_of_data ();
53 if (lim_data == 0)
54 get_lim_data ();
56 /* Find current end of memory and issue warning if getting near max */
57 cp = sbrk (0);
58 siz = cp - data_space_start;
60 if (warnfunction)
61 switch (warnlevel)
63 case 0:
64 if (siz > (lim_data / 4) * 3)
66 warnlevel++;
67 (*warnfunction) ("Warning: past 75% of memory limit");
69 break;
71 case 1:
72 if (siz > (lim_data / 20) * 17)
74 warnlevel++;
75 (*warnfunction) ("Warning: past 85% of memory limit");
77 break;
79 case 2:
80 if (siz > (lim_data / 20) * 19)
82 warnlevel++;
83 (*warnfunction) ("Warning: past 95% of memory limit");
85 break;
87 default:
88 (*warnfunction) ("Warning: past acceptable memory limits");
89 break;
92 if (EXCEEDS_ELISP_PTR (cp))
93 (*warnfunction) ("Warning: memory in use exceeds lisp pointer size");
95 result = sbrk (size);
96 if (result == (POINTER) -1)
97 return NULL;
98 return result;
101 /* Cause reinitialization based on job parameters;
102 also declare where the end of pure storage is. */
104 void
105 malloc_init (start, warnfun)
106 POINTER start;
107 void (*warnfun) ();
109 extern POINTER (* __morecore) (); /* From gmalloc.c */
111 if (start)
112 data_space_start = start;
113 lim_data = 0;
114 warnlevel = 0;
115 warnfunction = warnfun;
116 __morecore = &morecore_with_warning;