(mouse-drag-region-1): When remapping mouse-1 to mouse-2, go back to
[bpt/emacs.git] / src / vm-limit.c
CommitLineData
94d7c01a 1/* Functions for memory limit warnings.
0b5538bd
TTN
2 Copyright (C) 1990, 1992, 2002, 2003, 2004,
3 2005 Free Software Foundation, Inc.
94d7c01a
JA
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
e231fd42 9the Free Software Foundation; either version 2, or (at your option)
94d7c01a
JA
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
4fc5845f
LK
19the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20Boston, MA 02110-1301, USA. */
94d7c01a 21
3b672b8f 22#ifdef emacs
18160b98 23#include <config.h>
94d7c01a 24#include "lisp.h"
3b672b8f
RS
25#endif
26
27#ifndef emacs
28#include <stddef.h>
29typedef size_t SIZE;
30typedef void *POINTER;
31#define EXCEEDS_LISP_PTR(x) 0
32#endif
33
e231fd42 34#include "mem-limits.h"
94d7c01a
JA
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.
3b672b8f 41 3 -- 95% warning issued; keep warning frequently.
94d7c01a
JA
42*/
43static int warnlevel;
44
45/* Function to call to issue a warning;
46 0 means don't issue them. */
da396c5e 47static void (*warn_function) ();
94d7c01a 48
94d7c01a
JA
49/* Get more memory space, complaining if we're near the end. */
50
fd065466
RM
51static void
52check_memory_limits ()
94d7c01a 53{
968e9c04
AI
54#ifdef REL_ALLOC
55 extern POINTER (*real_morecore) ();
56#endif
134994ae
RM
57 extern POINTER (*__morecore) ();
58
968e9c04 59
94d7c01a 60 register POINTER cp;
46b3623d
RS
61 unsigned long five_percent;
62 unsigned long data_size;
94d7c01a
JA
63
64 if (lim_data == 0)
65 get_lim_data ();
3b672b8f 66 five_percent = lim_data / 20;
94d7c01a
JA
67
68 /* Find current end of memory and issue warning if getting near max */
968e9c04
AI
69#ifdef REL_ALLOC
70 if (real_morecore)
71 cp = (char *) (*real_morecore) (0);
72 else
73#endif
fd065466 74 cp = (char *) (*__morecore) (0);
da396c5e 75 data_size = (char *) cp - (char *) data_space_start;
94d7c01a 76
da396c5e 77 if (warn_function)
94d7c01a
JA
78 switch (warnlevel)
79 {
177c0ea7 80 case 0:
3b672b8f 81 if (data_size > five_percent * 15)
94d7c01a
JA
82 {
83 warnlevel++;
3b672b8f 84 (*warn_function) ("Warning: past 75% of memory limit");
94d7c01a
JA
85 }
86 break;
87
177c0ea7 88 case 1:
3b672b8f 89 if (data_size > five_percent * 17)
94d7c01a
JA
90 {
91 warnlevel++;
3b672b8f 92 (*warn_function) ("Warning: past 85% of memory limit");
94d7c01a
JA
93 }
94 break;
95
177c0ea7 96 case 2:
3b672b8f 97 if (data_size > five_percent * 19)
94d7c01a
JA
98 {
99 warnlevel++;
3b672b8f 100 (*warn_function) ("Warning: past 95% of memory limit");
94d7c01a
JA
101 }
102 break;
103
104 default:
3b672b8f 105 (*warn_function) ("Warning: past acceptable memory limits");
94d7c01a
JA
106 break;
107 }
108
3b672b8f
RS
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))
da396c5e 123 (*warn_function) ("Warning: memory in use exceeds lisp pointer size");
94d7c01a
JA
124}
125
126/* Cause reinitialization based on job parameters;
127 also declare where the end of pure storage is. */
128
129void
3b672b8f 130memory_warnings (start, warnfun)
94d7c01a
JA
131 POINTER start;
132 void (*warnfun) ();
133{
fd065466 134 extern void (* __after_morecore_hook) (); /* From gmalloc.c */
94d7c01a
JA
135
136 if (start)
137 data_space_start = start;
3b672b8f
RS
138 else
139 data_space_start = start_of_data ();
140
da396c5e 141 warn_function = warnfun;
fd065466 142 __after_morecore_hook = check_memory_limits;
b78e8d0a
AI
143
144#ifdef WINDOWSNT
145 /* Force data limit to be recalculated on each run. */
146 lim_data = 0;
147#endif
94d7c01a 148}
ab5796a9
MB
149
150/* arch-tag: eab04eda-1f69-447a-8d9f-95f0a3983ca5
151 (do not change this comment) */