(mouse-drag-region-1): When remapping mouse-1 to mouse-2, go back to
[bpt/emacs.git] / src / vm-limit.c
1 /* Functions for memory limit warnings.
2 Copyright (C) 1990, 1992, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
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.
11
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.
16
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. */
21
22 #ifdef emacs
23 #include <config.h>
24 #include "lisp.h"
25 #endif
26
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
33
34 #include "mem-limits.h"
35
36 /*
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.
42 */
43 static int warnlevel;
44
45 /* Function to call to issue a warning;
46 0 means don't issue them. */
47 static void (*warn_function) ();
48
49 /* Get more memory space, complaining if we're near the end. */
50
51 static void
52 check_memory_limits ()
53 {
54 #ifdef REL_ALLOC
55 extern POINTER (*real_morecore) ();
56 #endif
57 extern POINTER (*__morecore) ();
58
59
60 register POINTER cp;
61 unsigned long five_percent;
62 unsigned long data_size;
63
64 if (lim_data == 0)
65 get_lim_data ();
66 five_percent = lim_data / 20;
67
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;
76
77 if (warn_function)
78 switch (warnlevel)
79 {
80 case 0:
81 if (data_size > five_percent * 15)
82 {
83 warnlevel++;
84 (*warn_function) ("Warning: past 75% of memory limit");
85 }
86 break;
87
88 case 1:
89 if (data_size > five_percent * 17)
90 {
91 warnlevel++;
92 (*warn_function) ("Warning: past 85% of memory limit");
93 }
94 break;
95
96 case 2:
97 if (data_size > five_percent * 19)
98 {
99 warnlevel++;
100 (*warn_function) ("Warning: past 95% of memory limit");
101 }
102 break;
103
104 default:
105 (*warn_function) ("Warning: past acceptable memory limits");
106 break;
107 }
108
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;
121
122 if (EXCEEDS_LISP_PTR (cp))
123 (*warn_function) ("Warning: memory in use exceeds lisp pointer size");
124 }
125
126 /* Cause reinitialization based on job parameters;
127 also declare where the end of pure storage is. */
128
129 void
130 memory_warnings (start, warnfun)
131 POINTER start;
132 void (*warnfun) ();
133 {
134 extern void (* __after_morecore_hook) (); /* From gmalloc.c */
135
136 if (start)
137 data_space_start = start;
138 else
139 data_space_start = start_of_data ();
140
141 warn_function = warnfun;
142 __after_morecore_hook = check_memory_limits;
143
144 #ifdef WINDOWSNT
145 /* Force data limit to be recalculated on each run. */
146 lim_data = 0;
147 #endif
148 }
149
150 /* arch-tag: eab04eda-1f69-447a-8d9f-95f0a3983ca5
151 (do not change this comment) */